Index: trunk/instant_messenger/controller.php
===================================================================
--- trunk/instant_messenger/controller.php	(revision 55)
+++ trunk/instant_messenger/controller.php	(revision 151)
@@ -1,103 +1,85 @@
 <?php
-	//	Explode action from cExecuteForm function
-	$cExecuteFormReturn = false;
-   $returnMode = $_REQUEST['returnMode'];
- 	if($_POST['_action']) {
- 		if($_FILES) {
- 			$count_files = $_POST['countFiles'];
-			$array_files = array();
- 			for($idx = 1; $idx <= $count_files; $idx++) {
- 				if($_FILES['file_'.$idx] && !$_FILES['file_'.$idx]['error'])
- 					$array_files[] = $_FILES['file_'.$idx];
- 			}
- 			$_POST['FILES'] = $array_files;
- 		}
- 		list($app,$class,$method) = explode('.',@$_POST['_action']);
- 		$cExecuteFormReturn = true;
- 	}
- 	//	Explode action from cExecute function
- 	else if($_GET['action'])
-   {
-      unset($_GET['returnMode']);
-		list($app,$class,$method) = explode('.',@$_GET['action']);
-   }
-	// NO ACTION
-	else
-		return $_SESSION['response'] = 'false';
+if ( !$_GET['act'] )
+	echo "controller - #0 : invalid action";
+else
+{
+	#$header = getallheaders();
+	#if ( !$header['ThreadId'] )
+	#	echo "controller - #1 : invalid thread id";
+	#else
+	#{
+		#header('ThreadId: ' . $header['ThreadId']);
+		header('ThreadId: ' . $_GET['act']);
+		list($type, $file, $complement) = explode('.', $_GET['act']);
+		switch ( $type )
+		{
+			case '$this' :
+			case '$class' :
+			case '$obj' :
+				factory($file, $complement);
+				break;
+			case '$file' :
+			case '$xml' :
+			case '$js' :
+			case '$css' :
+				shop();
+				break;
+			default : echo "controller - #2 : invalid type";
+		}
+	#}
+}
 
-	// Load dinamically class file.
-	if($app == '$this')
-		$filename = 'inc/class.'.$class.'.inc.php';
-	else
-		$filename = '../'.$app.'/inc/class.'.$class.'.inc.php';
+exit(0);
 
-	include_once($filename);
+function factory($class = false, $method = false)
+{
+	if ( !$class || !$method )
+	{
+		echo "controller - #3 : invalid class or method";
+		return false;
+	}
 
-	// Create new Object  (class loaded).
+	# Load dinamically class file.
+	$filename = 'inc/class.'.$class.'.inc.php';
+	if ( !file_exists($filename) )
+	{
+		echo "controller - #4 : class not exists";
+		return false;
+	}
+	require_once $filename;
+
+	# Create new Object  (class loaded).
 	$obj = new $class;
-
-	// Prepare parameters for execution.
+	# Prepare parameters for execution.
 	$params = array();
 
-	// If array $_POST is not null , the submit method is POST.
-	if($_POST) {
-		$params = $_POST;
-	}
-	// If array $_POST is null , and the array $_GET > 1, the submit method is GET.
-	else if(count($_GET) > 1)	{
-		array_shift($_GET);
-		$params = $_GET;
+	$request_method = $_SERVER['REQUEST_METHOD'];
+	switch ( $request_method )
+	{
+		case 'GET' :
+			array_shift($_GET);
+			$params = $_GET;
+		break;
+		case 'POST' :
+			$params = $_POST;
+		break;
+		case 'HEAD' :
+		case 'PUT' :
+		default :
+			echo "controller - #5 : request method not avaible";
+			return false;
 	}
 
-	$result = array();
-
-
-	// if params is not empty, then class method with parameters.
-	if($params)
+	# if params is not empty, then class method with parameters.
+	if ( $params )
 		$result = $obj -> $method($params);
 	else
 		$result = $obj -> $method();
 
-	// Return result json string into xml object.
-	if(!$cExecuteFormReturn)
-   {
-      $dom = new DOMDocument;//('1.0', 'UTF-8');
+	printf("%s", $result);
+}
 
-      if ( $returnMode == 'JSON')
-      {
-         $root = $dom->appendChild(new DOMElement('retorno'));
-         encode($result, 'encode');
-         $result = ( !is_object($result) && !is_array($result) ) ? $result : json_encode($result);
-
-         $root->appendChild($dom->createCDATASection($result));
-      }
-      else
-		{
-			$_SESSION['phpgw_info']['instant_messenger']['debug2'] = $result;
-			$dom->loadXML('<retorno>' . utf8_encode($result) . '</retorno>');
-		}
-
-      $dom->normalizeDocument();
-		$retorno = $dom->saveXML();
-      header('Pragma: anytextexeptno-cache', true);
-      header('Content-type: text/xml, charset=UTF-8');
-		print $retorno;
-   }
-	else
-		$_SESSION['response'] = $result;
-
-   function encode(&$item, $val = 'encode')
-   {
-      switch( gettype($item) )
-      {
-         case 'object' :
-                     $item = get_object_vars($item);
-                     encode($item);
-         break;
-         case 'array' :
-                     array_walk_recursive($item, 'encode');
-         break;
-         default : $item = utf8_encode($item);
-      }
-   }
+function shop()
+{
+}
 ?>
