Index: /trunk/workflow/inc/class.so_userinterface.inc.php
===================================================================
--- /trunk/workflow/inc/class.so_userinterface.inc.php	(revision 1266)
+++ /trunk/workflow/inc/class.so_userinterface.inc.php	(revision 1269)
@@ -512,8 +512,9 @@
 			. " WHERE (f.area_id = a.area_id)"
 			. " AND (f.funcionario_status_id = s.funcionario_status_id)"
+			. " AND (f.organizacao_id = ?)"
 			. " AND (f.localidade_id = ?)"
 			. " AND (s.exibir = ?)";
 
-		$result = $this -> db -> query( $query, array( $locationID, 'S' ) );
+		$result = $this -> db -> query( $query, array( $organizationID, $locationID, 'S' ) );
 
 		$employees = $result -> GetArray( -1 );
@@ -566,4 +567,75 @@
 		return $output;
 	}
+
+	/**
+	 * Return the list of employees in alphabetical order
+	 * @param int $organizationID The organization ID
+	 * @return array The list o employees
+	 * @access public
+	 */
+	function getAlphabeticalEmployees( $organizationID )
+	{
+		$organizationID = ( int ) $organizationID;
+
+		// load the employees from the location
+		$query = "SELECT f.funcionario_id, f.organizacao_id, f.area_id, a.sigla AS area,"
+			. " COALESCE(f.funcionario_categoria_id, 0) AS funcionario_categoria_id"
+			. " FROM funcionario f, funcionario_status s, area a"
+			. " WHERE (f.area_id = a.area_id)"
+			. " AND (f.funcionario_status_id = s.funcionario_status_id)"
+			. " AND (f.organizacao_id = ?)"
+			. " AND (s.exibir = ?)";
+
+		$result = $this -> db -> query( $query, array( $organizationID, 'S' ) );
+
+		$employees = $result -> GetArray( -1 );
+		$cachedLDAP = $GLOBALS[ 'workflow' ][ 'factory' ] -> newInstance( 'CachedLDAP' );
+		$cachedLDAP -> setOperationMode( $cachedLDAP -> OPERATION_MODE_LDAP_DATABASE );
+
+		$categoriesCount = array( );
+		for ( $i = 0; $i < count( $employees ); $i++ )
+		{
+			// remove numeric fields
+			for ( $j = 0; $j < $result -> _numOfFields; $j++ )
+				unset( $employees[ $i ][ $j ] );
+
+			$employees[ $i ][ 'cn' ] = '';
+			$employees[ $i ][ 'telephoneNumber' ] = '';
+
+			// try to find the telephone number
+			$entry = $cachedLDAP -> getEntryByID( $employees[ $i ][ 'funcionario_id' ] );
+			if ( $entry )
+			{
+				$employees[ $i ][ 'telephoneNumber' ] = is_null( $entry[ 'telephonenumber' ] ) ? '' : $entry[ 'telephonenumber' ];
+				$employees[ $i ][ 'cn' ] = is_null( $entry[ 'cn' ] ) ? '' : $entry[ 'cn' ];
+				$employees[ $i ][ 'removed' ] = is_null( $entry[ 'last_update' ] );
+			}
+
+			// count the number of employees in each category
+			$categoryID = $employees[ $i ][ 'funcionario_categoria_id' ];
+			if ( isset( $categoriesCount[ $categoryID ] ) )
+				$categoriesCount[ $categoryID ]++;
+			else
+				$categoriesCount[ $categoryID ] = 1;
+		}
+
+		$usedCategories = array_keys( $categoriesCount );
+		$availableCategories = $this -> getCategoriesList( $organizationID );
+		$output = array( );
+		$output[ 'employees' ] = $employees;
+		$output[ 'categories' ] = array( );
+		foreach ( $availableCategories as $category )
+		{
+			if ( ! in_array( $category[ 'funcionario_categoria_id' ], $usedCategories ) )
+				continue;
+
+			$category[ 'contagem' ] = $categoriesCount[ $category[ 'funcionario_categoria_id' ] ];
+			$output[ 'categories' ][ ] = $category;
+		}
+
+		usort( $output[ 'employees' ], create_function( '$a,$b', 'return strcasecmp($a[\'cn\'],$b[\'cn\']);' ) );
+
+		return $output;
+	}
 }
 ?>
Index: /trunk/workflow/inc/class.bo_userinterface.inc.php
===================================================================
--- /trunk/workflow/inc/class.bo_userinterface.inc.php	(revision 1266)
+++ /trunk/workflow/inc/class.bo_userinterface.inc.php	(revision 1269)
@@ -1038,5 +1038,22 @@
 			return array( 'error' => 'Localidade não encontrada.' );
 
-		//usort( $employees['employees'], create_function( '$a,$b', 'return strcasecmp($a[\'cn\'],$b[\'cn\']);' ) );
+		return $employees;
+	}
+
+	/**
+	 * Return the list of employees in alphabetical order
+	 * @access public
+	 * @return array array of employees
+	 */
+	function getAlphabeticalEmployees( )
+	{
+		/* check for access */
+		if ( ( $checkWarnings = $this -> checkOrgchartAccess( ) ) !== true )
+			return $checkWarnings;
+
+		$employees = $this -> so -> getAlphabeticalEmployees( $this -> organizationInfo[ 'organizacao_id' ] );
+
+		if ( $employees === false )
+			return array( 'error' => 'Localidade não encontrada.' );
 
 		return $employees;
Index: /trunk/workflow/js/userinterface/orgchart.js
===================================================================
--- /trunk/workflow/js/userinterface/orgchart.js	(revision 1266)
+++ /trunk/workflow/js/userinterface/orgchart.js	(revision 1269)
@@ -36,5 +36,5 @@
 	content += '<li style="margin: 5px 5px 0 5px">Visualizar : <select>'
 	content += '<option>-- Selecione uma opção de visualização --</option>'
-	content += '<option onclick="">Alfabética</option>'
+	content += '<option onclick="getAlphabeticalEmployees( )">Alfabética</option>'
 	content += '<option onclick="getHierarchicalArea( );">Áreas</option>'
 	content += '<option onclick="getManning( )">Lotação</option>'
@@ -45,8 +45,4 @@
 	content += '</select></li>';
 	content += '<li><a href="#" onclick="window.open(\'' + enderecoImagem + '\', \'extwindow\'); return false;"><img src="templateFile.php?file=images/Process.gif">&nbsp;&nbsp;Gráfico</a></li>';
-	//content += '<li><a href="#" onclick="getCostCenters(); return false;"><img src="templateFile.php?file=images/coins.png">&nbsp;Centros de Custo</a></li>';
-	//content += '<li><a href="#" onclick="getHierarchicalArea(); return false;"><img src="templateFile.php?file=images/orgchart_tree.png">Lista Hierárquica</a></li>';
-	//content += '<li><a href="#" onclick="getAreaList(); return false;"><img src="templateFile.php?file=images/orgchart_list.png">&nbsp;&nbsp;Lista Alfabética</a></li>';
-	//content += '<li><a href="#" onclick="getCategoriesList(); return false;"><img src="templateFile.php?file=images/folder_green.png">&nbsp;&nbsp;Listar Vínculos</a></li>';
 	content += '<li><a href="#" onclick="printArea(); return false;"><img src="templateFile.php?file=images/imprimir.png" width="16">&nbsp;&nbsp;Imprimir</a></li>';
 	content += '<li><a><input type="text" name="search_term" id="search_term" onkeypress="if (((event.which) ? event.which : event.keyCode) == 13) $(\'search_span\').onclick(); return true;" /><span id="search_span" style="cursor: pointer;" onclick="tmp = $$(\'div#orgchartAreas a.destaque\'); if (tmp[0]) tmp[0].removeClassName(\'destaque\'); orgchartSearchEmployee($F(\'search_term\')); return false;">&nbsp;busca</span></a></li>';
@@ -374,4 +370,10 @@
 }
 
+function getAlphabeticalEmployees( )
+{
+	workflowUserInterfaceCurrentAreaID = 0;
+	cExecute('$this.bo_userinterface.getAlphabeticalEmployees', printEmployeesHandler);
+}
+
 function orgchartSearchEmployee(searchTerm)
 {
