Index: sandbox/2.4.1-3/prototype/config/Tonic.srv
===================================================================
--- sandbox/2.4.1-3/prototype/config/Tonic.srv	(revision 6439)
+++ sandbox/2.4.1-3/prototype/config/Tonic.srv	(revision 6473)
@@ -1,21 +1,2 @@
-
-[/maillast]
-MailLastResource = /mail/MailLastResource.php
-
-[/calendarlast]
-CalendarLastResource = /calendar/CalendarLastResource.php
-
-[/newslast]
-NewsLastResource = /news/NewsLastResource.php
-
-[/dynamiccontacts]
-DynamicContactsResource = /contact/DynamicContactsResource.php
-
-[/oi]
-DynamicContactDeleteResource = /contact/DynamicContactDeleteResource.php
-
-[/dynamiccontacts/:id]
-DynamicContactResource = /contact/DynamicContactResource.php
-
 [/token]
 TokenResource = /oauth/TokenResource.php
@@ -38,2 +19,8 @@
 [/group/:id]
 GroupResource = /catalog/GroupResource.php
+
+[/dynamiccontacts]
+DynamicContactsResource = /catalog/DynamicContactsResource.php
+
+[/dynamiccontact/:id]
+DynamicContactResource = /catalog/DynamicContactResource.php
Index: sandbox/2.4.1-3/prototype/config/dynamicContact.ini
===================================================================
--- sandbox/2.4.1-3/prototype/config/dynamicContact.ini	(revision 6351)
+++ sandbox/2.4.1-3/prototype/config/dynamicContact.ini	(revision 6473)
@@ -8,3 +8,4 @@
 mail = mail
 owner = owner
+number_of_messages = number_of_messages
 timestamp = timestamp
Index: sandbox/2.4.1-3/prototype/rest/catalog/DynamicContactsResource.php
===================================================================
--- sandbox/2.4.1-3/prototype/rest/catalog/DynamicContactsResource.php	(revision 6473)
+++ sandbox/2.4.1-3/prototype/rest/catalog/DynamicContactsResource.php	(revision 6473)
@@ -0,0 +1,253 @@
+<?php
+
+if( !defined( 'ROOTPATH' ) )
+    define( 'ROOTPATH', dirname(__FILE__).'/..' );
+
+require_once(ROOTPATH.'/rest/hypermedia/hypermedia.php');
+
+use prototype\api\Config as Config;
+
+class DynamicContactsResource extends Resource {
+
+    /**
+     * Retorna uma lista de contatos recentes 
+     *
+     * @license    http://www.gnu.org/copyleft/gpl.html GPL
+     * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)
+     * @sponsor    Caixa Econômica Federal
+     * @author     José Vicente Tezza Jr. 
+     * @return     Retorna uma lista de contatos recentes
+     * @access     public
+     * */
+    function get($request) {
+
+	$response = new Response($request);
+	$response->addHeader('Content-type', 'aplication/json');
+	$response->code = Response::OK;
+
+	$h = new Hypermedia();
+	$c = new Collection($request->resources, 'DynamicContactsResource');
+
+	try {
+//	    $this->secured();
+
+            $dynamicContacts = Controller::find( 
+						array( 'concept' => 'dynamicContact' ), 
+						false, 
+						array( 'filter' => array( '=', 'owner',  Config::me("uidNumber") ), 
+						'order' => array('number_of_messages','name','mail'), 
+						'orderDesc' => array(true, false, false) ) 
+	    );
+
+	    //Se nao foi encontrado contatos na consulta
+	    if($dynamicContacts===false){
+		$error = new Error();
+		$error->setCode(Response::NOTFOUND);
+		$error->setTitle('Dynamic Contacts not found');
+		$error->setDescription('Dynamic Contacts not found.');
+
+		$c->setError($error);
+		$h->setCollection($c);
+
+		$response->code = Response::NOTFOUND;
+		$response->body = $h->getHypermedia($request->accept[10][0]);
+		return $response;
+	    }
+
+            foreach($dynamicContacts as $value){
+		$d = new Data();
+                $i = new Item($request->resources, 'DynamicContactsResource', $value['id']);
+
+		$d->setName('name');
+                $d->setValue($value['name']);
+                $d->setPrompt('Nome do Contato Recente');
+                $d->setDataType('string');
+                $d->setMaxLength('100');
+                $d->setMinLength(null);
+                $d->setRequired(true);
+
+                $i->addData($d);
+
+		$d = new Data();
+                $d->setName('mail');
+                $d->setValue($value['mail']);
+                $d->setPrompt('Email do Contato Recente');
+                $d->setDataType('string');
+                $d->setMaxLength('100');
+                $d->setMinLength(null);
+                $d->setRequired(true);
+
+                $i->addData($d);
+
+		$d = new Data();
+                $d->setName('number_of_messages');
+                $d->setValue($value['number_of_messages']);
+                $d->setPrompt('Quantidade de mensagens enviadas');
+                $d->setDataType('integer');
+                $d->setMaxLength('100');
+                $d->setMinLength(null);
+                $d->setRequired(false);
+
+                $i->addData($d);
+
+                $l = new Link();
+
+                $l->setHref('');
+                $l->setRel('delete');
+                $l->setAlt('Remover');
+                $l->setPrompt('Remover');
+                $l->setRender('link');
+
+                $i->addLink($l);
+
+                $l = new Link();
+                $l->setHref('');
+                $l->setRel('put');
+                $l->setAlt('Atualizar');
+                $l->setPrompt('Atualizar');
+                $l->setRender('link');
+
+                $i->addLink($l);
+
+                $l = new Link();
+                $l->setHref('/dynamiccontact/'.$value['id']);
+                $l->setRel('get');
+                $l->setAlt('Buscar');
+                $l->setPrompt('Buscar');
+                $l->setRender('link');
+
+                $i->addLink($l);
+                $c->addItem($i);
+	    }
+
+            $t = new Template();
+            $d = new Data();
+
+            $d->setName('name');
+            $d->setValue(null);
+            $d->setPrompt('Nome do Contato Recente');
+            $d->setDataType('string');
+            $d->setMaxLength(100);
+            $d->setMinLength(null);
+            $d->setRequired(true);
+
+            $t->addData($d);
+
+            $d = new Data();
+            $d->setName('mail');
+            $d->setValue(null);
+            $d->setPrompt('Email do Contato Recente');
+            $d->setDataType('string');
+            $d->setMaxLength(100);
+            $d->setMinLength(null);
+            $d->setRequired(true);
+
+            $t->addData($d);
+
+            $d = new Data();
+            $d->setName('number_of_messages');
+            $d->setValue(null);
+            $d->setPrompt('Quantidade de mensagens enviadas');
+            $d->setDataType('integer');
+            $d->setMaxLength(100);
+            $d->setMinLength(null);
+            $d->setRequired(false);
+
+            $t->addData($d);
+
+            $c->setTemplate($t);
+
+            $h->setCollection($c);
+
+	}catch (Exception $ex){
+		$error = new Error();
+		$error->setCode(Response::INTERNALSERVERERROR);
+		$error->setTitle('Internal Server Error');
+		$error->setDescription($ex);
+
+		$c->setError($error);
+		$h->setCollection($c);
+
+		$response->code = Response::INTERNALSERVERERROR;
+		$response->body = $h->getHypermedia($request->accept[10][0]);
+		return $response;
+	}
+
+	$response->body = $h->getHypermedia($request->accept[10][0]);
+	return $response;
+    }
+
+    /**
+     * Salva um contato recente
+     *
+     * @license    http://www.gnu.org/copyleft/gpl.html GPL
+     * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)
+     * @sponsor    Caixa Econômica Federal
+     * @author     José Vicente Tezza Jr. 
+     * @return     retorna a uri do contato recente
+     * @access     public
+     * */
+     function post($request){
+
+	if(count($_POST) == 0){
+	        $response = new Response($request);
+		$response->code = Response::INTERNALSERVERERROR;
+		return $response;
+	}
+
+	//recupera os atributos definidos no conceito 'user'
+	$map = Config::get('dynamicContact', 'PostgreSQL.mapping');
+
+	$params = array();
+	foreach($_POST as $key => $value){
+
+		if( !isset( $map[ $key ] ) || $key == 'id' || $key == 'timestamp' || $key == 'number_of_messages' ){
+			continue;
+		}
+		$params[$key] = $value;
+	}
+
+	if(count($params) == 0){
+	        $response = new Response($request);
+		$response->code = Response::INTERNALSERVERERROR;
+		return $response;
+	}
+
+
+        $response = new Response($request);
+//      $response->addHeader('Content-type', 'aplication/json');
+        $response->code = Response::CREATED;
+
+	
+	//completar os atributos
+	$params['owner'] 		= Config::me("uidNumber");
+	$params['number_of_messages'] 	= '1';
+	$params['timestamp'] 		= time();
+
+
+        try{
+
+//                      $this->secured();
+     
+                    $idDynamicContact = Controller::create(
+							array('concept' => 'dynamicContact'), 
+							$params
+		    );
+
+		    if(!$idDynamicContact){
+			throw new Exception(Controller::service('PostgreSQL')->error);
+		    }
+
+        }catch (Exception $ex){
+                $response->code = Response::INTERNALSERVERERROR;
+                return $response;
+        }
+
+$response->body = json_encode(array('abc'=>'123'));
+
+        return $response;
+     }
+
+
+}
+?>
Index: sandbox/2.4.1-3/prototype/rest/catalog/DynamicContactResource.php
===================================================================
--- sandbox/2.4.1-3/prototype/rest/catalog/DynamicContactResource.php	(revision 6473)
+++ sandbox/2.4.1-3/prototype/rest/catalog/DynamicContactResource.php	(revision 6473)
@@ -0,0 +1,323 @@
+<?php
+
+if( !defined( 'ROOTPATH' ) )
+    define( 'ROOTPATH', dirname(__FILE__).'/..' );
+
+require_once(ROOTPATH.'/rest/hypermedia/hypermedia.php');
+
+use prototype\api\Config as Config;
+
+class DynamicContactResource extends Resource {
+
+    /**
+     * Retorna um contato recente 
+     *
+     * @license    http://www.gnu.org/copyleft/gpl.html GPL
+     * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)
+     * @sponsor    Caixa Econômica Federal
+     * @author     José Vicente Tezza Jr. 
+     * @return     Retorna um contato recente
+     * @access     public
+     * */
+     function get($request, $id){
+
+        $response = new Response($request);
+        $response->addHeader('Content-type', 'aplication/json');
+        $response->code = Response::OK;
+
+        $h = new Hypermedia();
+        $c = new Collection($request->resources, 'DynamicContactResource');
+
+        try {
+//            $this->secured();
+
+            $dynamicContacts = Controller::find( 
+                                                array( 'concept' => 'dynamicContact' ), 
+                                                false, 
+                                                array( 'filter' => array( 'AND', array( '=', 'owner',  Config::me("uidNumber") ) , array('=', 'id', $id) ) )  
+            );
+
+            //Se nao foi encontrado contatos na consulta
+            if($dynamicContacts===false){
+                $error = new Error();
+                $error->setCode(Response::NOTFOUND);
+                $error->setTitle('Dynamic Contact not found');
+                $error->setDescription('Dynamic Contact not found.');
+
+                $c->setError($error);
+                $h->setCollection($c);
+
+                $response->code = Response::NOTFOUND;
+                $response->body = $h->getHypermedia($request->accept[10][0]);
+                return $response;
+            }
+
+
+            $t = new Template();
+            $d = new Data();
+
+            $d->setName('name');
+            $d->setValue(null);
+            $d->setPrompt('Nome do Contato Recente');
+            $d->setDataType('string');
+            $d->setMaxLength(100);
+            $d->setMinLength(null);
+            $d->setRequired(true);
+
+            $t->addData($d);
+
+            $d = new Data();
+            $d->setName('mail');
+            $d->setValue(null);
+            $d->setPrompt('Email do Contato Recente');
+            $d->setDataType('string');
+            $d->setMaxLength(100);
+            $d->setMinLength(null);
+            $d->setRequired(true);
+
+            $t->addData($d);
+
+            $d = new Data();
+            $d->setName('number_of_messages');
+            $d->setValue(null);
+            $d->setPrompt('Quantidade de mensagens enviadas');
+            $d->setDataType('integer');
+            $d->setMaxLength(100);
+            $d->setMinLength(null);
+            $d->setRequired(false);
+
+            $t->addData($d);
+
+            $c->setTemplate($t);
+
+            $d = new Data();
+            $d->setName('id');
+            $d->setValue($dynamicContacts[0]['id']);
+            $d->setPrompt('Identificador do Contato Recente');
+            $d->setDataType('integer');
+            $d->setMaxLength(null);
+            $d->setMinLength(null);
+            $d->setRequired(true);
+
+            $c->addData($d);
+
+            $d = new Data();
+
+            $d->setName('name');
+            $d->setValue($dynamicContacts[0]['name']);
+            $d->setPrompt('Nome do Contato Recente');
+            $d->setDataType('string');
+            $d->setMaxLength('100');
+            $d->setMinLength(null);
+            $d->setRequired(true);
+
+            $c->addData($d);
+
+            $d = new Data();
+            $d->setName('mail');
+            $d->setValue($dynamicContacts[0]['mail']);
+            $d->setPrompt('Email do Contato Recente');
+            $d->setDataType('string');
+            $d->setMaxLength('100');
+            $d->setMinLength(null);
+            $d->setRequired(true);
+
+            $c->addData($d);
+
+            $d = new Data();
+            $d->setName('number_of_messages');
+            $d->setValue($dynamicContacts[0]['number_of_messages']);
+            $d->setPrompt('Quantidade de mensagens enviadas');
+            $d->setDataType('integer');
+            $d->setMaxLength('100');
+            $d->setMinLength(null);
+            $d->setRequired(false);
+
+            $c->addData($d);
+
+
+            $l = new Link();
+
+            $l->setHref('');
+            $l->setRel('delete');
+            $l->setAlt('Remover');
+            $l->setPrompt('Remover');
+            $l->setRender('link');
+
+            $c->addLink($l);
+
+            $l = new Link();
+            $l->setHref('');
+            $l->setRel('put');
+            $l->setAlt('Atualizar');
+            $l->setPrompt('Atualizar');
+            $l->setRender('link');
+
+            $c->addLink($l);
+
+	    $h->setCollection($c);
+ 
+
+        }catch (Exception $ex){
+                $error = new Error();
+                $error->setCode(Response::INTERNALSERVERERROR);
+                $error->setTitle('Internal Server Error');
+                $error->setDescription($ex);
+
+                $c->setError($error);
+                $h->setCollection($c);
+
+                $response->code = Response::INTERNALSERVERERROR;
+                $response->body = $h->getHypermedia($request->accept[10][0]);
+                return $response;
+        }
+
+        $response->body = $h->getHypermedia($request->accept[10][0]);
+        return $response;
+     }   
+
+    /**
+     * Atualiza um contato recente
+     *
+     * @license    http://www.gnu.org/copyleft/gpl.html GPL
+     * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)
+     * @sponsor    Caixa Econômica Federal
+     * @author     José Vicente Tezza Jr. 
+     * @return     retorna a uri do contato recente
+     * @access     public
+     * */
+     function put($request, $id){
+$post = $request->dataDecoded;
+
+        if(count($post) == 0){
+                $response = new Response($request);
+                $response->code = Response::INTERNALSERVERERROR;
+                return $response;
+        }
+
+        //recupera os atributos definidos no conceito 'user'
+        $map = Config::get('dynamicContact', 'PostgreSQL.mapping');
+
+        $params = array();
+        foreach($post as $key => $value){
+
+                if( !isset( $map[ $key ] ) || $key == 'id' || $key == 'timestamp' || $key == 'number_of_messages' ){
+                        continue;
+                }
+                $params[$key] = $value;
+        }
+
+        if(count($params) == 0){
+                $response = new Response($request);
+                $response->code = Response::INTERNALSERVERERROR;
+                return $response;
+        }
+
+        //completar os atributos
+        $params['owner']                = Config::me("uidNumber");
+        $params['number_of_messages']   = '1';
+        $params['timestamp']            = time();
+	$params['id']			= $id;
+
+
+        $response = new Response($request);
+//      $response->addHeader('Content-type', 'aplication/json');
+//        $response->code = Response::NOCONTENT;
+
+        try{
+
+//                      $this->secured();
+
+		$dynamicContact = Controller::read(
+						array( 'concept' => 'dynamicContact' ),
+                                                false,
+						array( 'filter' => array( 
+									'AND', 
+									array('=', 'owner',  Config::me("uidNumber") ), 
+									array('=', 'id', $id) )  ) 
+		);
+
+
+                //Se existe o recurso
+                if($dynamicContact){
+		    $params['number_of_messages']++;
+
+                    $dynamicContact = Controller::update(
+                                                        array('concept' => 'dynamicContact'),
+                                                        $params
+                    );
+
+                    if(!$dynamicContact){
+                        throw new Exception(Controller::service('PostgreSQL')->error);
+                    }
+
+                }
+                else{
+
+                    $idDynamicContact = Controller::create(
+                                                        array('concept' => 'dynamicContact'),
+                                                        $params
+                    );
+
+                    if(!$idDynamicContact){
+                        throw new Exception(Controller::service('PostgreSQL')->error);
+                    }
+
+                }
+
+        }catch (Exception $ex){
+                $response->code = Response::INTERNALSERVERERROR;
+                return $response;
+        }
+
+        return $response;
+
+     }   
+
+    /**
+     * Remove um contato recente
+     *
+     * @license    http://www.gnu.org/copyleft/gpl.html GPL
+     * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)
+     * @sponsor    Caixa Econômica Federal
+     * @author     José Vicente Tezza Jr. 
+     * @access     public
+     * */
+     function delete($request, $id){
+
+	$response = new Response($request);
+//	$response->addHeader('Content-type', 'aplication/json');
+	$response->code = Response::NOCONTENT;
+
+	try{
+		//Verifica se o recurso existe
+		$responseGET = $this->get($request, $id);
+		$code = $responseGET->code;
+
+		//Se existe o recurso
+		if($code == Response::OK){
+
+//			$this->secured();
+
+			$delete = Controller::delete(array('concept' => 'dynamicContact'), false, array('filter' => array('=', 'id', $id)));
+
+			if(!$delete){
+				throw new Exception(Controller::service('PostgreSQL')->error);
+			}
+		}
+		else{
+	                $response->code = Response::NOTFOUND;
+		}
+
+	}catch (Exception $ex){
+                $response->code = Response::INTERNALSERVERERROR;
+                return $response;
+	}
+
+$response->body = json_encode(array('ABC'=>'123'));
+
+        return $response;
+     }
+
+}
+?>
Index: sandbox/2.4.1-3/home.php
===================================================================
--- sandbox/2.4.1-3/home.php	(revision 6352)
+++ sandbox/2.4.1-3/home.php	(revision 6473)
@@ -99,7 +99,4 @@
 	}
 
-/*
-//ESSE TRECHO DE CÃDIGO DEVE SER INSERIDO NOVAMENTE POSTERIORMENTE !!!!!!!!!!!
-
         // Default Applications (Home Page) 
         $default_apps = Array(                  
@@ -145,5 +142,5 @@
                                 $appname = 'expressoMail';
                         }*/
-/*
+
                         if(array_search($appname, $default_apps) !== False){
                                 $thisd = 1;
@@ -186,41 +183,5 @@
         }
         print '</table>';
-*/
 
-
-
-//Inicio	
-	echo '
-            <link rel="Stylesheet" type="text/css" href="prototype/plugins/jquery/jquery-ui.css" />					
-    
-            <script type="text/javascript" src="prototype/plugins/jquery/jquery.min.js"></script>
-        
-            <script type="text/javascript" src="prototype/plugins/jquery/jquery-ui.min.js"></script>
-            <script type="text/javascript" src="prototype/plugins/jquery/jquery-ui.custom.min.js"></script>
-            <script src="prototype/plugins/json2/json2.js" language="javascript"></script>
-            <script src="prototype/plugins/ejs/ejs.js" language="javascript"></script>
-            <script src="prototype/plugins/store/jquery.store.js" language="javascript"></script>
-            
-            <script src="prototype/api/datalayer.js" language="javascript"></script>	
-           
-            <script type="text/javascript" src="prototype/plugins/datejs/date-pt-BR.js"></script>
-            <script type="text/javascript" src="prototype/plugins/datejs/sugarpak.js"></script>
-            <script type="text/javascript" src="prototype/plugins/datejs/parser.js"></script>
-
-	    <script type="text/javascript" src="prototype/plugins/countdown/jquery.countdown.min.js"></script>
-	    <script type="text/javascript" src="prototype/plugins/countdown/jquery.countdown-pt-BR.js"></script>
-
-	    <script type="text/javascript" src="prototype/modules/home/js/home.js"></script>
-	    <link rel="Stylesheet" type="text/css" href="prototype/modules/home/css/home.css" />	
-        ';
-
-	echo'
-	    <tr>
-		<td>
-		    <div class="portlets" style="width: 100%;"></div>
-		<td>
-	    </tr>';
-
-//Fim	
 	$GLOBALS['phpgw']->common->phpgw_footer();
 ?>
