Index: sandbox/2.4.3-expresso-rest/negrinha/setup/default_records.inc.php
===================================================================
--- sandbox/2.4.3-expresso-rest/negrinha/setup/default_records.inc.php	(revision 7355)
+++ sandbox/2.4.3-expresso-rest/negrinha/setup/default_records.inc.php	(revision 7355)
@@ -0,0 +1,50 @@
+<?php
+
+  /**************************************************************************\
+  * eGroupWare - Setup                                                       *
+  * http://www.egroupware.org                                                *
+  * --------------------------------------------                             *
+  *  This program is free software; you can redistribute it and/or modify it *
+  *  under the terms of the GNU General Public License as published by the   *
+  *  Free Software Foundation; either version 2 of the License, or (at your  *
+  *  option) any later version.                                              *
+  \**************************************************************************/
+
+$secret = substr(md5(rand().rand()), 0, 16); //Gera senha aleatoria
+
+$oProc->query("INSERT INTO rest_client (client_id, client_secret) values (1, '$secret');");
+$dados = array();
+$oProc->query("SELECT * FROM phpgw_config WHERE config_app='phpgwapi'");
+while ($oProc->next_record())
+{
+    $test = @unserialize($oProc->f('config_value'));
+    if($test)
+        $dados[$oProc->f('config_name')] = $test;
+    else
+        $dados[$oProc->f('config_name')] = $oProc->f('config_value');
+}
+
+/*
+Cria e configura o arquivo REST.ini 
+*/
+require_once dirname(__FILE__) . '/../../prototype/api/config.php';
+
+use prototype\api\Config as Config;
+
+$config = array();
+$config['baseUri'] = $dados['webserver_url'].'/rest';
+$config['oauth']['url_token'] = 'http://' . $_SERVER['HTTP_HOST'] . $dados['webserver_url'].'/rest/token';
+$config['oauth']['client_id'] = 1;
+$config['oauth']['client_secret'] = $secret;
+
+$serverID = "001";
+$config['ServersRest-'.$serverID]['serverID'] = $serverID;
+$config['ServersRest-'.$serverID]['serverName'] = $_SERVER['HTTP_HOST'];
+$config['ServersRest-'.$serverID]['serverDescription'] = 'Expresso - ' . $_SERVER['HTTP_HOST'];
+$config['ServersRest-'.$serverID]['serverUrl'] = 'http://' . $_SERVER['HTTP_HOST'] . $dados['webserver_url'];
+$config['ServersRest-'.$serverID]['serverContext'] = '/rest/';
+$config['ServersRest-'.$serverID]['serverStatus'] = 'true';
+
+Config::writeIniFile($config , dirname(__FILE__) . '/../../prototype/config/REST.ini', true);
+
+?>
Index: sandbox/2.4.3-expresso-rest/negrinha/setup/tables_current.inc.php
===================================================================
--- sandbox/2.4.3-expresso-rest/negrinha/setup/tables_current.inc.php	(revision 7355)
+++ sandbox/2.4.3-expresso-rest/negrinha/setup/tables_current.inc.php	(revision 7355)
@@ -0,0 +1,87 @@
+<?php
+  /**************************************************************************\
+  * eGroupWare                                                               *
+  * http://www.egroupware.org                                                *
+  * --------------------------------------------                             *
+  *  This program is free software; you can redistribute it and/or modify it *
+  *  under the terms of the GNU General Public License as published by the   *
+  *  Free Software Foundation; either version 2 of the License, or (at your  *
+  *  option) any later version.                                              *
+  \**************************************************************************/
+
+//Verifica se tem permissÃ£o na pasta de configuraÃ§Ã£o antes de comeÃ§ar a instalaÃ§Ã£o do modulo.
+require_once dirname(__FILE__) . '/../../prototype/api/config.php';
+use prototype\api\Config as Config;
+
+if( Config::writeIniFile(array() , dirname(__FILE__) . '/../../prototype/config/REST.ini', true) === false )
+{
+	echo "<div style='color:red;font-size:14px'>Permission failure when trying to write in folder \"/prototype/config/\". Grant write permission in folder and try again. </div>";
+	die(); //Mata o restante da execuÃ§Ã£o.
+}
+///
+
+	$phpgw_baseline = array(
+		
+		'rest_access_token' => array(
+			'fd' => array(
+				'id' => array('type' => 'auto','nullable' => False),
+				'oauth_token' => array('type' => 'varchar','precision' => '40', 'nullable' => false),
+				'client_id' => array('type' => 'varchar', 'precision' => '40','nullable' => false),
+				'user_id' => array('type' => 'int', 'precision' => '16','nullable' => false),
+				'expires' => array('type' => 'int', 'varchar' => '8','nullable' => false),
+				'scope' => array('type' => 'varchar', 'varchar' => '255','nullable' => True),
+				'refresh_token' => array('type' => 'varchar', 'precision' => '40','nullable' => false)
+			),
+			'pk' => array('id'),
+			'fk' => array(),
+			'ix' => array(),
+			'uc' => array()
+		),
+		
+		'rest_auth_code' => array(
+			'fd' => array(
+				'id' => array('type' => 'auto','nullable' => False),
+				'redirect_uri' => array('type' => 'varchar','precision' => '255', 'nullable' => true),
+				'client_id' => array('type' => 'varchar', 'precision' => '40','nullable' => false),
+				'user_id' => array('type' => 'int', 'precision' => '16','nullable' => false),
+				'expires' => array('type' => 'int', 'varchar' => '8','nullable' => false),
+				'scope' => array('type' => 'varchar', 'varchar' => '255','nullable' => True),
+				'refresh_token' => array('type' => 'varchar', 'precision' => '40','nullable' => false)
+			),
+			'pk' => array('id'),
+			'fk' => array(),
+			'ix' => array(),
+			'uc' => array()
+		),
+	
+		'rest_client' => array(
+			'fd' => array(
+				'id' => array('type' => 'auto','nullable' => False),
+				'redirect_uri' => array('type' => 'varchar','precision' => '255', 'nullable' => true),
+				'client_id' => array('type' => 'varchar', 'precision' => '40','nullable' => false),
+				'client_secret' => array('type' => 'varchar', 'precision' => '40','nullable' => false)
+			),
+			'pk' => array('id'),
+			'fk' => array(),
+			'ix' => array(),
+			'uc' => array()
+		),
+
+		'rest_refresh_token' => array(
+			'fd' => array(
+				'id' => array('type' => 'auto','nullable' => False),
+				'refresh_token' => array('type' => 'varchar','precision' => '40', 'nullable' => false),
+				'client_id' => array('type' => 'varchar', 'precision' => '40','nullable' => false),
+				'user_id' => array('type' => 'int', 'precision' => '16','nullable' => false),
+				'expires' => array('type' => 'int', 'varchar' => '8','nullable' => false),
+				'scope' => array('type' => 'varchar', 'varchar' => '255','nullable' => True),
+				'refresh_token' => array('type' => 'varchar', 'precision' => '40','nullable' => false)
+			),
+			'pk' => array('id'),
+			'fk' => array(),
+			'ix' => array(),
+			'uc' => array()
+		),
+
+	);
+?>
Index: sandbox/2.4.3-expresso-rest/negrinha/setup/tables_update.inc.php
===================================================================
--- sandbox/2.4.3-expresso-rest/negrinha/setup/tables_update.inc.php	(revision 7355)
+++ sandbox/2.4.3-expresso-rest/negrinha/setup/tables_update.inc.php	(revision 7355)
@@ -0,0 +1,14 @@
+<?php
+	/**************************************************************************\
+	* ExpressoLivre - Setup                                                     *
+	* http://www.expressolivre.org                                              *
+	* --------------------------------------------                             *
+	* This program is free software; you can redistribute it and/or modify it  *
+	* under the terms of the GNU General Public License as published by the    *
+	* Free Software Foundation; either version 2 of the License, or (at your   *
+	* option) any later version.                                               *
+	\**************************************************************************/
+
+	
+        
+?>
Index: sandbox/2.4.3-expresso-rest/negrinha/setup/setup.inc.php
===================================================================
--- sandbox/2.4.3-expresso-rest/negrinha/setup/setup.inc.php	(revision 7355)
+++ sandbox/2.4.3-expresso-rest/negrinha/setup/setup.inc.php	(revision 7355)
@@ -0,0 +1,36 @@
+<?php
+	/**************************************************************************\
+	* Expresso - Seu Novo Modulo                                               *
+	* http://www.expressolivre.org                                             *
+	* --------------------------------------------                             *
+	*  This program is free software; you can redistribute it and/or modify it *
+	*  under the terms of the GNU General Public License as published by the   *
+	*  Free Software Foundation; either version 2 of the License, or (at your  *
+	*  option) any later version.                                              *
+	\**************************************************************************/
+
+	$setup_info['rest']['name']      	= 'negrinha';
+	$setup_info['rest']['title']     	= 'REST API' ;
+	$setup_info['rest']['enable']		= 1;
+	
+	/* Ao incrementar versão, não esquecer de declarar função do tables_update.inc.php*/
+	$setup_info['rest']['version']   	= '1.000';
+	$setup_info['rest']['app_order']	= 9;
+
+	$setup_info['rest']['tables'][]		=  'rest_access_token';
+	$setup_info['rest']['tables'][]		=  'rest_auth_code';
+	$setup_info['rest']['tables'][]		=  'rest_client';
+	$setup_info['rest']['tables'][]		=  'rest_refresh_token';
+
+	$setup_info['rest']['license']  = 'GPL';
+	$setup_info['rest']['description'] = 'Modulo de Suport a REST ExpressoLivre';	
+
+	/* The hooks this app includes, needed for hooks registration */
+	$setup_info['negrinha']['hooks'][] = 'admin';
+
+	/* Dependencies for this app to work */
+	$setup_info['negrinha']['depends']['appname'] = array(
+		 'appname' => 'phpgwapi',
+		 'versions' => Array('2.4.2')
+	);
+?>
Index: sandbox/2.4.3-expresso-rest/negrinha/inc/class.uiconfig.inc.php
===================================================================
--- sandbox/2.4.3-expresso-rest/negrinha/inc/class.uiconfig.inc.php	(revision 7355)
+++ sandbox/2.4.3-expresso-rest/negrinha/inc/class.uiconfig.inc.php	(revision 7355)
@@ -0,0 +1,211 @@
+<?php
+
+class uiconfig
+{
+	public $public_functions = array(
+		'config' 		=> true,
+		'deleteServer'	=> true,
+		'editServer'	=> true
+	);
+
+	
+	function __construct()
+	{
+		$GLOBALS['phpgw']->common->phpgw_header();
+		
+		echo parse_navbar();
+	}
+	
+	public function config( $params = false )
+	{
+		if( !$GLOBALS['phpgw']->acl->check('run',1,'admin') )
+		{
+			$GLOBALS['phpgw']->redirect_link('/admin/index.php');
+		}
+		
+		$GLOBALS['phpgw_info']['flags']['app_header'] = 'Configuração do Módulo';
+		
+		$table_servers = "";
+		
+		if( $_POST['back'] )
+		{
+			$GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/admin/index.php'));
+		}
+		else
+		{
+			if( $_POST && $params == false )
+			{
+				$this->save($_POST);
+			}
+			
+			$servers = $this->readFile();
+			
+			if( count($servers) > 0 )
+			{
+				$serversTable = "";
+				
+				foreach( $servers as $key => $value )
+				{
+					if( substr($key, 0, 11) == "ServersRest")
+					{
+						$table_servers .= "<tr>";
+						$table_servers .= "	<td>".$value['serverName']."</td>";
+						$table_servers .= "	<td>".$value['serverDescription']."</td>";
+						$table_servers .= "	<td>".$value['serverUrl']."</td>";
+						$table_servers .= "	<td>".$value['serverContext']."</td>";
+						$table_servers .= "	<td>".( ($value['serverStatus'] == 1 ) ? "Habilitado" : "Desabilitado" )."</td>";
+						$table_servers .= " <td><a href='".$GLOBALS['phpgw']->link('/index.php','menuaction=negrinha.uiconfig.editServer&serverID='.$value['serverID'].'')."'>Editar</a></td>";
+						$table_servers .= " <td><a href='".$GLOBALS['phpgw']->link('/index.php','menuaction=negrinha.uiconfig.deleteServer&serverID='.$value['serverID'].'')."'>Excluir</a></td>";
+						$table_servers .= "</tr>";
+					}
+				}	
+			}
+	
+			
+			$GLOBALS['phpgw']->template->set_file(array('negrinha'=>'config.tpl'));
+			$GLOBALS['phpgw']->template->set_block('negrinha','pagina');	
+			$GLOBALS['phpgw']->template->set_var( array(
+															'table_servers'	=> $table_servers,
+															'server_id'		=> (($params && is_array($params) ) ? $params['serverID'] : ""),
+															'server_name'	=> (($params && is_array($params) ) ? $params['serverName'] : ""),
+															'server_description'	=> (($params && is_array($params) ) ? $params['serverDescription'] : ""),
+															'server_url'	=> (($params && is_array($params) ) ? $params['serverUrl'] : ""),
+															'server_rest'	=> (($params && is_array($params) ) ? $params['serverContext'] : "")
+														));
+		
+			$GLOBALS['phpgw']->template->pparse('out','pagina');
+		}
+	}
+
+	public function deleteServer()
+	{
+		if( $_GET['serverID'] )
+		{
+			$serverID = $_GET['serverID'];
+			
+			$servers = $this->readFile();
+			
+			foreach( $servers as $key => $value )
+			{
+				if( substr($key, 0, 11) == "ServersRest")
+				{
+					if( $value['serverID'] == $serverID )
+					{
+						unset( $servers[$key] );
+					}
+				}
+			}
+			
+			if( !$this->writeFile($servers) )
+				echo "Error : Permission failure when trying to write in the file ";
+			else
+				$this->config();
+		}
+	}
+	
+	public function editServer()
+	{
+		if($_GET['serverID'] )
+		{
+			$serverID = $_GET['serverID'];
+			
+			$servers = $this->readFile();
+			
+			foreach( $servers as $key => $value )
+			{
+				if( substr($key, 0, 11) == "ServersRest")
+				{
+					if( $value['serverID'] == $serverID )
+					{
+						$server = $servers[$key];
+					}
+				}
+			}
+			
+		}
+		
+		$this->config($server);
+	}
+
+	private function save($params)
+	{
+		$fileConfig = parse_ini_file( __DIR__ . '/../../prototype/config/REST.ini', true );
+		
+		if( $params['server_id'] )
+		{
+			$serverID = $params['server_id'];
+			
+			$fileConfig['ServersRest-'.$serverID]['serverID'] = $serverID;
+			$fileConfig['ServersRest-'.$serverID]['serverName'] = $params['server_name'];
+			$fileConfig['ServersRest-'.$serverID]['serverDescription'] = $params['server_description'];
+			$fileConfig['ServersRest-'.$serverID]['serverUrl'] = $params['server_url'];
+			$fileConfig['ServersRest-'.$serverID]['serverContext'] = $params['server_rest'];
+			$fileConfig['ServersRest-'.$serverID]['serverStatus'] = 'true';
+		}
+		else
+		{
+			$keys = array_keys($fileConfig);
+			
+			foreach($keys as $k => $v)
+			{
+				if( substr($v, 0, 11) == "ServersRest")
+					$ID = $fileConfig[$v]['serverID'];
+			}				
+			
+			$serverID = ((int)$ID + 1);
+			if( strlen($serverID) <= 2 )
+				$serverID = ( strlen($serverID) > 1 ) ? "0".$serverID : "00".$serverID;
+			$fileConfig['ServersRest-'.$serverID]['serverID'] = $serverID;
+			$fileConfig['ServersRest-'.$serverID]['serverName'] = $params['server_name'];
+			$fileConfig['ServersRest-'.$serverID]['serverDescription'] = $params['server_description'];
+			$fileConfig['ServersRest-'.$serverID]['serverUrl'] = $params['server_url'];
+			$fileConfig['ServersRest-'.$serverID]['serverContext'] = $params['server_rest'];
+			$fileConfig['ServersRest-'.$serverID]['serverStatus'] = 'true';
+		}
+		
+		$this->writeFile($fileConfig);
+	}
+
+	private function readFile()
+	{
+		$fileConfig = array();
+		
+		if( file_exists(__DIR__ . '/../../prototype/config/REST.ini') )
+		{
+			$fileConfig = parse_ini_file( __DIR__ . '/../../prototype/config/REST.ini', true );
+		}
+
+		return $fileConfig;
+	}
+	
+	private function writeFile($config)
+	{
+		$path = __DIR__ . '/../../prototype/config/REST.ini';
+
+		$content = "";
+
+		foreach( $config as $key => $value )
+		{
+			if(is_array($value))
+			{
+				$content .= "[".$key."]\n";
+				
+				foreach( $value as $ikey => $ivalue )
+					$content .= $ikey ."=". $ivalue . "\n";
+			}
+			else
+			{
+				$content .= $key . "=" . $value . "\n";				
+			}
+		}
+
+		if( file_put_contents($path, $content) === false)
+		{
+			return false;
+		}
+		
+		return true;
+	}
+}
+
+?>
Index: sandbox/2.4.3-expresso-rest/negrinha/inc/hook_admin.inc.php
===================================================================
--- sandbox/2.4.3-expresso-rest/negrinha/inc/hook_admin.inc.php	(revision 7355)
+++ sandbox/2.4.3-expresso-rest/negrinha/inc/hook_admin.inc.php	(revision 7355)
@@ -0,0 +1,22 @@
+<?php
+
+if( !isset($GLOBALS['phpgw_info']) )
+{
+	$GLOBALS['phpgw_info']['flags'] = array(
+		'currentapp' => "negrinha",
+		'nonavbar'   => true,
+		'noheader'   => true
+	);
+}
+
+// Only Modify the $file and $title variables.....
+	$title = $GLOBALS['phpgw_info']['flags']['currentapp'];
+	
+	$file = array(
+		'Site Configuration' 	=> $GLOBALS['phpgw']->link('/index.php','menuaction=negrinha.uiconfig.config')
+	);
+
+//Do not modify below this line
+	display_section($appname,$title,$file);
+
+?>
Index: sandbox/2.4.3-expresso-rest/negrinha/index.php
===================================================================
--- sandbox/2.4.3-expresso-rest/negrinha/index.php	(revision 7355)
+++ sandbox/2.4.3-expresso-rest/negrinha/index.php	(revision 7355)
@@ -0,0 +1,11 @@
+<?php
+
+	$phpgw_flags = Array(
+		'currentapp'	=>	'negrinha'
+	);
+
+	$GLOBALS['phpgw_info']['flags'] = $phpgw_flags;
+	
+	include('../header.inc.php');
+
+?>
Index: sandbox/2.4.3-expresso-rest/negrinha/templates/default/config.tpl
===================================================================
--- sandbox/2.4.3-expresso-rest/negrinha/templates/default/config.tpl	(revision 7355)
+++ sandbox/2.4.3-expresso-rest/negrinha/templates/default/config.tpl	(revision 7355)
@@ -0,0 +1,76 @@
+<!-- BEGIN pagina -->
+<link rel='stylesheet' type='text/css' href='/negrinha/templates/css/style.css'>
+
+<div id="globalDiv">
+	<div id="contentDiv">
+		
+		<div>
+			<p>
+				<img src="/negrinha/templates/default/images/navbar.png">
+				<span style="font-size:9pt; font-weight:bold;margin-left:10px;">Configuração da API Rest</span>
+			</p>
+		</div>
+		
+		<fieldset>
+			<form method="POST" action="index.php?menuaction=negrinha.uiconfig.config">
+				<!-- Server Name -->
+				<label for="server_name">Nome do Servidor .:</label>
+				<input type="hidden" name="server_id" value="{server_id}">
+				<input type="text" name="server_name" value="{server_name}" size="50" maxlength="50">
+				<br>
+				
+				<!-- Server Description -->
+				<label for="server_description">Descrição .:</label>
+				<input type="text" name="server_description" value="{server_description}" size="30" maxlength="50">
+				<br>
+				
+				<!-- Server URL -->
+				<label for="server_url">URL .:</label>
+				<input type="text" name="server_url" value="{server_url}" size="50" maxlength="50">
+				<br>
+	
+				<!-- Server Rest -->
+				<label for="server_rest">API Rest .:</label>
+				<input type="text" name="server_rest" value="{server_rest}" size="50" maxlength="50">
+				<br>
+				
+				<!-- Server Status -->
+				<label for="server_status">Status do Servidor .:</label>
+				<select name="server_status">
+					<option value="true">Habilitado</option>
+					<option value="false">Desabilitado</option>
+				</select>
+				<br>
+				
+				<div style="float:left;">
+					<input type="submit" name="save" value="Salvar"/>
+				</div>
+				
+				<div style="float:right;">
+					<input type="submit" name="back" value="Voltar"/>
+				</div>	
+			</form>
+		</fieldset>		
+		
+		<br clear="all"/>
+		
+		<div style="margin-top:10px;">
+			<table style="border:1px solid #000; width:100%">
+				<tr align="left">
+					<th>Nome do Servidor</th>
+					<th>Descrição</th>
+					<th>URL</th>
+					<th>API Rest</th>
+					<th>Estado do Servidor</th>
+					<th>Editar</th>
+					<th>Excluir</th>
+				</tr>
+				{table_servers}
+			</table>
+		</div>
+	
+	</div>
+</div>
+
+<!-- END pagina -->
+
Index: sandbox/2.4.3-expresso-rest/negrinha/templates/css/style.css
===================================================================
--- sandbox/2.4.3-expresso-rest/negrinha/templates/css/style.css	(revision 7355)
+++ sandbox/2.4.3-expresso-rest/negrinha/templates/css/style.css	(revision 7355)
@@ -0,0 +1,35 @@
+label, input
+{
+	font-size:9pt;
+	display: block;
+	float: left;
+}
+
+label
+{	
+	
+	text-align: left;
+	width: 120px;
+	padding-right: 10px;
+	padding-bottom: 8px;
+}
+
+fieldset {
+	border: solid 1px #000;
+}
+
+br {
+	clear: left;
+}
+
+#globalDiv
+{
+	width: 800px;
+	margin:0 auto;         
+}
+
+#contentDiv
+{
+	padding: 5px;
+	background-color: #eee;
+}
