Index: branches/2.2.0.1/contactcenter/inc/class.ui_data.inc.php
===================================================================
--- branches/2.2.0.1/contactcenter/inc/class.ui_data.inc.php	(revision 3795)
+++ branches/2.2.0.1/contactcenter/inc/class.ui_data.inc.php	(revision 3970)
@@ -410,5 +410,10 @@
 					$ids = false;
 					$ids = $this->search($_GET['data']);
-					return $this->get_cards_data('search', '1', $ids);
+					$data = unserialize($_GET['data']);
+                                        $dontPaginate = false;
+                                        if (isset($data['ccAddGroup'])){
+                                            $dontPaginate = true;
+                                        }
+					return $this->get_cards_data('search', '1', $ids, $dontPaginate);
 
 				case 'email_win':
@@ -479,5 +484,5 @@
 
 		*/
-		function set_catalog($id_catalog)
+		function set_catalog($id_catalog, $echo=true)
 		{
 			$id_catalog = str_replace('\\"', '"', $id_catalog);
@@ -515,11 +520,24 @@
 				}
 
-				echo serialize(array(
-					'status' => 'ok',
-					'catalog' => $catalog_info['class'],
-					'external' => $catalog_info['external']?true:false,
-                                        'resetCC_actual_letter' => $resetCC_actual_letter,
-					'perms'  => $perms
-				));
+                                if ($echo)
+                                {
+                                    echo serialize(array(
+                                            'status' => 'ok',
+                                            'catalog' => $catalog_info['class'],
+                                            'external' => $catalog_info['external']?true:false,
+                                            'resetCC_actual_letter' => $resetCC_actual_letter,
+                                            'perms'  => $perms
+                                    ));
+                                }
+                                else
+                                    {
+                                        return serialize(array(
+                                            'status' => 'ok',
+                                            'catalog' => $catalog_info['class'],
+                                            'external' => $catalog_info['external']?true:false,
+                                            'resetCC_actual_letter' => $resetCC_actual_letter,
+                                            'perms'  => $perms
+                                        ));
+                                    }
 
 				return;
@@ -678,5 +696,5 @@
 				using the new array 'msg','status','data' schema.
 		*/
-		function get_cards_data($letter, $page, $ids)
+		function get_cards_data($letter, $page, $ids, $dontPaginate = false)
 		{
 			if( $ids )
@@ -1203,5 +1221,5 @@
 				{
 					//echo 'N_entries: '.$n_entries.'<br>';
-					$this->page_info['n_pages'] = ceil($n_entries/($this->page_info['n_cards'] ? $this->page_info['n_cards'] : 1));
+					$this->page_info['n_pages'] = ceil(($n_entries/($this->page_info['n_cards']) && !$dontPaginate ? $this->page_info['n_cards'] : 1));
 				}
 				else
@@ -1273,5 +1291,5 @@
 					$this->page_info['actual_letter']  = $letter;
 					$this->page_info['actual_entries'] = $ids;
-					$this->page_info['n_pages'] = ceil(count($ids)/($this->page_info['n_cards'] ? $this->page_info['n_cards'] : 1));
+					$this->page_info['n_pages'] = ceil((count($ids)/($this->page_info['n_cards']) && !$dontPaginate ? $this->page_info['n_cards'] : 1));
 				}
 			}
@@ -1307,7 +1325,8 @@
 
 				//echo 'Page: '.$page.'<br>';
-				$id_i = (($page-1)*$this->page_info['n_cards']);
-				$id_f = $id_i + $this->page_info['n_cards'];
 				$n_entries = count($this->page_info['actual_entries']);
+                                $n_cards = $dontPaginate? $n_entries : $this->page_info['n_cards'];
+				$id_i = (($page-1)*$n_cards);
+				$id_f = $id_i + $n_cards;
 
 				//echo 'ID_I: '.$id_i.'<br>';
@@ -1583,4 +1602,5 @@
 				$final[8] = $this->page_info['actual_catalog']['class'];
 				$final[9] = $count;
+                                $final[11] = $this->bo->catalog_level;
 
 
@@ -1827,5 +1847,5 @@
 			@param string $sdata Serialized data
 		*/
-		function quick_add($sdata)
+		function quick_add($sdata, $echo=true)
 		{
 
@@ -1839,10 +1859,20 @@
 			if (!$tdata)
 			{
+                            if ($echo)
+                            {
 				echo serialize(array(
 					'msg'    => lang('Problems on adding your Contact. Invalid Data came from client. No Contact added!'),
 					'status' => 'abort'
 				));
-
+                            
 				return;
+                            }
+                            else
+                                {
+                                    return serialize(array(
+					'msg'    => lang('Problems on adding your Contact. Invalid Data came from client. No Contact added!'),
+					'status' => 'abort'
+                                    ));
+                                }
 			}
 
@@ -1855,4 +1885,6 @@
 				$str_contact = "\r\n - ".implode("\r\n - ",$contact);
 
+                            if ($echo)
+                            {
 				echo serialize(array(
 					'msg'    => lang('Problems on adding your Contact. The email "%1" already exists in: %2',$tdata[4], $str_contact),
@@ -1861,4 +1893,13 @@
 
 				return;
+                            }
+                            else
+                                {
+                                    return serialize(array(
+					'msg'       => lang('Problems on adding your Contact. The email "%1" already exists in: %2',$tdata[4], $str_contact),
+					'status'    => 'alreadyExists',
+                                        'id_connection'  => $contact[1]
+                                    ));
+                                }
 			}
 
@@ -1873,19 +1914,41 @@
 			$boPeople = CreateObject('contactcenter.bo_people_catalog');
 
-			if ($boPeople ->quick_add($data))
-			{
-				$this->page_info['changed'] = true;
-
-				echo serialize(array(
-					'msg'    => lang('Entry added with success!'),
-					'status' => 'ok'
-				));
+			$result = $boPeople->quick_add($data);
+			if ($result)
+			{
+                            $this->page_info['changed'] = true;
+
+                            if ($echo)
+                            {
+                                echo serialize(array(
+                                    'msg'    => lang('Entry added with success!'),
+                                    'status' => 'ok'
+                                ));
+                            }
+                            else
+                                {
+                                    return serialize(array(
+                                        'msg'    => lang('Entry added with success!'),
+                                        'status' => 'ok',
+                                        'conn'   => $boPeople->get_connections($result)
+                                    ));
+                                }
 			}
 			else
 			{
-				echo serialize(array(
-					'msg'    => lang('Problems on adding your Contact. No Contact added!'),
-					'status' => 'error'
-				));
+                            if ($echo)
+                            {
+                                echo serialize(array(
+                                    'msg'    => lang('Problems on adding your Contact. No Contact added!'),
+                                    'status' => 'error'
+                                ));
+                            }
+                            else
+                                {
+                                    echo serialize(array(
+                                        'msg'    => lang('Problems on adding your Contact. No Contact added!'),
+                                        'status' => 'error'
+                                    ));
+                                }
 			}
 
@@ -1924,5 +1987,49 @@
 			$data['contact_in_list'] = $new_tdata[1];
 			$data['id_group'] = $new_tdata[2];
-
+                        $acumulatedErrors = '';
+
+                        $actualCatalog = $this->get_actual_catalog();
+                        for ($i = 0; $i < count($data['contact_in_list']); $i++)
+                        {
+                            if (preg_match('/ldap:.*:.*/', $data['contact_in_list'][$i])) // from ldap
+                            {
+                                list(, $level, $dn) = explode(':', $data['contact_in_list'][$i]);
+
+                                // pesquisa os dados, insere no catálogo e modifica
+                                // a entrada em $data['contact_in_list'][$i]
+                                $set_catalog = $this->set_catalog($level, false);
+                                $contact_data = unserialize($this->get_catalog_add_contact($dn, false));
+                                $tmp_contact[] = $contact_data[0][0];
+                                $tmp_contact[] = $contact_data[1][0];
+                                $tmp_contact[] = $contact_data[2][0];
+                                $tmp_contact[] = $contact_data[3][0];
+                                $tmp_contact[] = $contact_data[4][0];
+
+                                // Determinar o id_connection
+                                $id_contact = unserialize($this->quick_add(serialize($tmp_contact), false));
+
+                                switch ($id_contact['status'])
+                                {
+                                    case 'ok' :
+                                        foreach ($id_contact['conn'] as $connection)
+                                        {
+                                            if ($connection['id_type'] == 1)
+                                            {
+                                                $data['contact_in_list'][$i] = $connection['id_connection'];
+                                            }
+                                        }
+                                        break;
+
+                                    case 'alreadyExists': // if e-mail exists get their id_connection from people_catalog
+                                        $data['contact_in_list'][$i] = $id_contact['id_connection'];
+
+                                    default:
+                                        $acumulatedErrors += $id_contact['msg']."\n";
+                                }
+                                unset($tmp_contact);
+
+                            }
+                        }
+                        $set_catalog = $this->set_catalog($actualCatalog['data'], false); // retorna ao catálogo original.
 			$boGroup = CreateObject('contactcenter.bo_group_manager');
 			$id = $boGroup -> add_group($data);
@@ -1940,5 +2047,6 @@
 			{
 				echo serialize(array(
-					'msg'    => lang('Problems on adding your Group. Be sure that a group with this name do not exists'),
+					'msg'    => lang('Problems on adding your Contact. No Contact added!').
+                                            "\n".$acumulatedErrors,
 					'status' => 'error'
 				));
@@ -3456,5 +3564,5 @@
 		}
 
-		function get_catalog_add_contact($id){
+		function get_catalog_add_contact($id, $echo=true){
 
 			$array_participants = array();
@@ -3475,5 +3583,12 @@
 
 			ldap_close($ds);
-			echo serialize($array_participants);
+                        if ($echo)
+                        {
+                            echo serialize($array_participants);
+                        }
+                        else
+                            {
+                                return serialize($array_participants);
+                            }
 		}
 
