[795] | 1 | <?php |
---|
| 2 | |
---|
| 3 | /** |
---|
| 4 | * @package Workflow |
---|
| 5 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 6 | * @author Sidnei Augusto Drovetto Jr. - drovetto@gmail.com |
---|
| 7 | */ |
---|
| 8 | class so_userinterface |
---|
| 9 | { |
---|
| 10 | /** |
---|
| 11 | * @var object database object |
---|
| 12 | * @access public |
---|
| 13 | */ |
---|
| 14 | var $db; |
---|
| 15 | |
---|
| 16 | /** |
---|
| 17 | * Constructor |
---|
| 18 | * @access public |
---|
| 19 | * @return object |
---|
| 20 | */ |
---|
| 21 | function so_userinterface() |
---|
| 22 | { |
---|
[2372] | 23 | $this->db =& Factory::getInstance('WorkflowObjects')->getDBWorkflow()->Link_ID; |
---|
[795] | 24 | $this->db->SetFetchMode(ADODB_FETCH_ASSOC); |
---|
| 25 | } |
---|
| 26 | |
---|
| 27 | /** |
---|
| 28 | * Obtain the subnet of an IP Address based on the numer of bits of the subnet |
---|
| 29 | * @param string $ip The IP Address |
---|
| 30 | * @param int $bits Number of bits of the subnet |
---|
| 31 | * @return string The subnet of the IP |
---|
| 32 | * @access private |
---|
| 33 | */ |
---|
| 34 | private function getSubnet($ip, $bits) |
---|
| 35 | { |
---|
| 36 | $octets = explode('.', $ip); |
---|
| 37 | $output = array(); |
---|
| 38 | for ($i = 0; $i < 4; $i++) |
---|
| 39 | { |
---|
| 40 | if ($bits >= 8) |
---|
| 41 | { |
---|
| 42 | $output[] = $octets[$i]; |
---|
| 43 | $bits -= 8; |
---|
| 44 | continue; |
---|
| 45 | } |
---|
| 46 | $output[] = $octets[$i] & bindec(str_repeat('1', $bits) . str_repeat('0',8 - $bits)); |
---|
| 47 | $bits = 0; |
---|
| 48 | } |
---|
| 49 | return implode('.', $output); |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | /** |
---|
| 53 | * Get External Applications |
---|
| 54 | * @access public |
---|
| 55 | * @return array list of external applications |
---|
| 56 | */ |
---|
| 57 | function getExternalApplications() |
---|
| 58 | { |
---|
| 59 | /* load the intranet subnetworks */ |
---|
| 60 | $oldDB = $GLOBALS['phpgw']->db; |
---|
| 61 | $GLOBALS['phpgw']->db = $GLOBALS['ajax']->db; |
---|
[2418] | 62 | $submasksString = Settings::get('workflow', 'intranet_subnetworks'); |
---|
[795] | 63 | $GLOBALS['phpgw']->db = $oldDB; |
---|
| 64 | |
---|
| 65 | $userIP = getenv('REMOTE_ADDR'); |
---|
| 66 | if (getenv('HTTP_X_FORWARDED_FOR')) |
---|
| 67 | { |
---|
| 68 | $tmpIP = explode(',', getenv('HTTP_X_FORWARDED_FOR')); |
---|
| 69 | $userIP = $tmpIP[0]; |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | /* check if the user has access to intranet applications, i.e., is in the intranet */ |
---|
| 73 | $showIntranetApplications = false; |
---|
| 74 | $submasks = explode(';', $submasksString); |
---|
| 75 | foreach ($submasks as $submask) |
---|
| 76 | { |
---|
| 77 | list($ip,$bits) = explode('/', trim($submask) . '/32', 2); |
---|
| 78 | if ($this->getSubnet($ip, $bits) == $this->getSubnet($userIP, $bits)) |
---|
| 79 | { |
---|
| 80 | $showIntranetApplications = true; |
---|
| 81 | break; |
---|
| 82 | } |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | $preOutput = array(); |
---|
| 86 | $output = array(); |
---|
| 87 | |
---|
| 88 | /* select the sites that the user can access */ |
---|
| 89 | $externalApplicationsID = $GLOBALS['ajax']->acl->getUserGroupPermissions('APX', $_SESSION['phpgw_info']['workflow']['account_id']); |
---|
| 90 | if (!empty($externalApplicationsID)) |
---|
| 91 | { |
---|
[2372] | 92 | $result = Factory::getInstance('WorkflowObjects')->getDBGalaxia()->Link_ID->query("SELECT DISTINCT external_application_id, name, address, image, authentication, intranet_only FROM egw_wf_external_application WHERE (external_application_id IN (" . implode(', ', $externalApplicationsID) . ")) ORDER BY name"); |
---|
[795] | 93 | $preOutput = $result->GetArray(-1); |
---|
| 94 | |
---|
| 95 | /* keep only associative elments and check if the user can access an intranet application */ |
---|
| 96 | for ($i = 0; $i < count($preOutput); $i++) |
---|
| 97 | { |
---|
| 98 | if (($preOutput[$i]['intranet_only'] == '1') && (!$showIntranetApplications)) |
---|
| 99 | continue; |
---|
| 100 | |
---|
| 101 | for ($j = 0; $j < $result->_numOfFields; $j++) |
---|
| 102 | unset($preOutput[$i][$j]); |
---|
| 103 | $output[] = $preOutput[$i]; |
---|
| 104 | } |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | return $output; |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | /** |
---|
| 111 | * Get User Organization ID |
---|
| 112 | * @param int $userID User identifier |
---|
| 113 | * @return mixed Informações sobre a organização ou false em caso de erro. |
---|
| 114 | * @access public |
---|
| 115 | */ |
---|
| 116 | function getUserOrganization($userID) |
---|
| 117 | { |
---|
| 118 | $query = "SELECT o.organizacao_id, o.nome, o.descricao, o.url_imagem, o.ativa FROM funcionario f, organizacao o WHERE (o.organizacao_id = f.organizacao_id) AND (f.funcionario_id = ?)"; |
---|
| 119 | $result = $this->db->query($query, array((int) $userID)); |
---|
| 120 | |
---|
| 121 | $output = $result->fetchRow(DB_FETCHMODE_ASSOC); |
---|
| 122 | if (!$output) |
---|
| 123 | return false; |
---|
| 124 | |
---|
| 125 | for ($i = 0; $i < $result->_numOfFields; $i++) |
---|
| 126 | unset($output[$i]); |
---|
| 127 | |
---|
| 128 | return $output; |
---|
| 129 | } |
---|
| 130 | |
---|
| 131 | /** |
---|
| 132 | * Get cost center list |
---|
| 133 | * @param int $organizationID The organization ID |
---|
| 134 | * @return array Lista de centros de custo |
---|
| 135 | * @access public |
---|
| 136 | */ |
---|
| 137 | function getCostCenters($organizationID) |
---|
| 138 | { |
---|
| 139 | $result = $this->db->query("SELECT nm_centro_custo, grupo, descricao FROM centro_custo WHERE (organizacao_id = ?) ORDER BY descricao", array($organizationID)); |
---|
| 140 | |
---|
| 141 | $output = $result->GetArray(-1); |
---|
| 142 | for ($i = 0; $i < count($output); $i++) |
---|
| 143 | for ($j = 0; $j < $result->_numOfFields; $j++) |
---|
| 144 | unset($output[$i][$j]); |
---|
| 145 | |
---|
| 146 | return $output; |
---|
| 147 | } |
---|
| 148 | |
---|
| 149 | /** |
---|
| 150 | * Get hierarchical Area |
---|
| 151 | * @return array |
---|
| 152 | * @access public |
---|
| 153 | */ |
---|
| 154 | function getHierarchicalArea($organizationID, $parent = null, $depth = 0) |
---|
| 155 | { |
---|
| 156 | if (is_null($parent)){ |
---|
| 157 | $query = "SELECT a.area_id, a.sigla, a.titular_funcionario_id FROM area a"; |
---|
| 158 | $query .=" INNER JOIN area_status a_s ON (a_s.area_status_id = a.area_status_id)"; |
---|
| 159 | $query .=" WHERE (a.superior_area_id IS NULL) AND (a.organizacao_id = ?) AND (a.ativa = 'S') ORDER BY a_s.nivel, a.sigla"; |
---|
| 160 | $result = $this->db->query($query, array($organizationID)); |
---|
| 161 | } else { |
---|
| 162 | $query = "SELECT a.area_id, a.sigla, a.titular_funcionario_id FROM area a"; |
---|
| 163 | $query .=" INNER JOIN area_status a_s ON (a_s.area_status_id = a.area_status_id)"; |
---|
| 164 | $query .=" WHERE (a.superior_area_id = ?) AND (a.ativa = 'S') ORDER BY a_s.nivel, a.sigla"; |
---|
| 165 | $result = $this->db->query($query, array($parent)); |
---|
| 166 | } |
---|
| 167 | |
---|
| 168 | $output = $result->GetArray(-1); |
---|
| 169 | for ($i = 0; $i < count($output); $i++) |
---|
| 170 | { |
---|
| 171 | for ($j = 0; $j < $result->_numOfFields; $j++) |
---|
| 172 | unset($output[$i][$j]); |
---|
| 173 | |
---|
| 174 | $output[$i]['children'] = $this->getHierarchicalArea($organizationID, $output[$i]['area_id'], $depth + 1); |
---|
| 175 | $output[$i]['depth'] = $depth; |
---|
| 176 | } |
---|
| 177 | |
---|
| 178 | return $output; |
---|
| 179 | } |
---|
| 180 | |
---|
| 181 | /** |
---|
| 182 | * Get organization area list |
---|
| 183 | * @return array |
---|
| 184 | * @access public |
---|
| 185 | */ |
---|
| 186 | function getAreaList($organizationID) |
---|
| 187 | { |
---|
| 188 | $result = $this->db->query("SELECT area_id, sigla FROM area WHERE (organizacao_id = ?) AND (ativa = 'S') ORDER BY sigla", array($organizationID)); |
---|
| 189 | |
---|
| 190 | $output = $result->GetArray(-1); |
---|
| 191 | for ($i = 0; $i < count($output); $i++) |
---|
| 192 | for ($j = 0; $j < $result->_numOfFields; $j++) |
---|
| 193 | unset($output[$i][$j]); |
---|
| 194 | |
---|
| 195 | return $output; |
---|
| 196 | } |
---|
| 197 | |
---|
| 198 | /** |
---|
| 199 | * Get organization categories list |
---|
| 200 | * @param int $organizationID The organization ID |
---|
| 201 | * @return array The categories list |
---|
| 202 | * @access public |
---|
| 203 | */ |
---|
| 204 | function getCategoriesList($organizationID) |
---|
| 205 | { |
---|
| 206 | $output = $this->db->query('SELECT funcionario_categoria_id, descricao FROM funcionario_categoria WHERE (organizacao_id = ?)', array($organizationID))->GetArray(); |
---|
| 207 | $numerOfEmployees = $this->db->GetAssoc('SELECT COALESCE(f.funcionario_categoria_id, 0) AS funcionario_categoria_id, COUNT(*) FROM funcionario f, funcionario_status fs WHERE (f.organizacao_id = ?) AND (f.funcionario_status_id = fs.funcionario_status_id) AND (fs.exibir = \'S\') GROUP BY funcionario_categoria_id', array($organizationID)); |
---|
| 208 | |
---|
| 209 | $output[] = array( |
---|
| 210 | 'funcionario_categoria_id' => 0, |
---|
| 211 | 'descricao' => 'Sem Vínculo' |
---|
| 212 | ); |
---|
| 213 | |
---|
| 214 | foreach ($output as &$row) |
---|
| 215 | $row['contagem'] .= (isset($numerOfEmployees[$row['funcionario_categoria_id']]) ? $numerOfEmployees[$row['funcionario_categoria_id']] : 0); |
---|
| 216 | |
---|
| 217 | return $output; |
---|
| 218 | } |
---|
| 219 | |
---|
| 220 | /** |
---|
| 221 | * Get Area Employees |
---|
| 222 | * @param int $areaID |
---|
| 223 | * @param int $organizationID |
---|
| 224 | * @return array |
---|
| 225 | * @access public |
---|
| 226 | */ |
---|
| 227 | function getAreaEmployees($areaID, $organizationID) |
---|
| 228 | { |
---|
| 229 | $organizationID = (int) $organizationID; |
---|
| 230 | $areaID = (int) $areaID; |
---|
| 231 | |
---|
| 232 | /* gather some info from the area */ |
---|
[2056] | 233 | $areaInfo = $this->db->query('SELECT COALESCE(a.titular_funcionario_id, -1) AS titular_funcionario_id, COALESCE(s.funcionario_id, -1) AS substituto_funcionario_id FROM area a LEFT OUTER JOIN substituicao s ON ((a.area_id = s.area_id) AND (CURRENT_DATE BETWEEN s.data_inicio AND s.data_fim)) WHERE (a.organizacao_id = ?) AND (a.area_id = ?)', array($organizationID, $areaID))->GetArray(-1); |
---|
[795] | 234 | if (empty($areaInfo)) |
---|
| 235 | return false; |
---|
| 236 | $areaInfo = $areaInfo[0]; |
---|
| 237 | $supervisors = '{' . implode(', ', $areaInfo) . '}'; |
---|
| 238 | |
---|
| 239 | /* load the employees from the area */ |
---|
| 240 | $query = "SELECT f.funcionario_id, f.organizacao_id, f.area_id, COALESCE(f.funcionario_categoria_id, 0) AS funcionario_categoria_id FROM funcionario f, funcionario_status s WHERE ((f.area_id = ?) OR (f.funcionario_id = ANY (?))) AND (f.funcionario_status_id = s.funcionario_status_id) AND (s.exibir = ?)"; |
---|
| 241 | $result = $this->db->query($query, array($areaID, $supervisors, 'S')); |
---|
| 242 | |
---|
| 243 | $employees = $result->GetArray(-1); |
---|
[2372] | 244 | $cachedLDAP = Factory::newInstance('CachedLDAP'); |
---|
[1310] | 245 | $cachedLDAP->setOperationMode($cachedLDAP->OPERATION_MODE_NORMAL); |
---|
[795] | 246 | $categoriesCount = array(); |
---|
| 247 | for ($i = 0; $i < count($employees); $i++) |
---|
| 248 | { |
---|
| 249 | /* remove numeric fields */ |
---|
| 250 | for ($j = 0; $j < $result->_numOfFields; $j++) |
---|
| 251 | unset($employees[$i][$j]); |
---|
| 252 | |
---|
| 253 | $employees[$i]['cn'] = ''; |
---|
| 254 | $employees[$i]['telephoneNumber'] = ''; |
---|
| 255 | if (in_array($employees[$i]['funcionario_id'], $areaInfo)) |
---|
| 256 | $employees[$i]['chief'] = ($employees[$i]['funcionario_id'] == $areaInfo['titular_funcionario_id']) ? 1 : 2; |
---|
| 257 | |
---|
| 258 | /* try to find the telephone number */ |
---|
| 259 | $entry = $cachedLDAP->getEntryByID($employees[$i]['funcionario_id']); |
---|
| 260 | if ($entry) |
---|
| 261 | { |
---|
| 262 | $employees[$i]['telephoneNumber'] = is_null($entry['telephonenumber']) ? '' : $entry['telephonenumber']; |
---|
| 263 | $employees[$i]['cn'] = is_null($entry['cn']) ? '' : $entry['cn']; |
---|
| 264 | $employees[$i]['removed'] = is_null($entry['last_update']); |
---|
| 265 | } |
---|
| 266 | |
---|
| 267 | /* count the number of employees in each category */ |
---|
| 268 | $categoryID = $employees[$i]['funcionario_categoria_id']; |
---|
| 269 | if (isset($categoriesCount[$categoryID])) |
---|
| 270 | $categoriesCount[$categoryID]++; |
---|
| 271 | else |
---|
| 272 | $categoriesCount[$categoryID] = 1; |
---|
| 273 | } |
---|
| 274 | $usedCategories = array_keys($categoriesCount); |
---|
| 275 | $availableCategories = $this->getCategoriesList($organizationID); |
---|
| 276 | $output = array(); |
---|
| 277 | $output['employees'] = $employees; |
---|
| 278 | $output['categories'] = array(); |
---|
| 279 | foreach ($availableCategories as $category) |
---|
| 280 | { |
---|
| 281 | if (!in_array($category['funcionario_categoria_id'], $usedCategories)) |
---|
| 282 | continue; |
---|
| 283 | |
---|
| 284 | $category['contagem'] = $categoriesCount[$category['funcionario_categoria_id']]; |
---|
| 285 | $output['categories'][] = $category; |
---|
| 286 | } |
---|
| 287 | |
---|
| 288 | usort($output['employees'], create_function('$a,$b', 'return strcasecmp($a[\'cn\'],$b[\'cn\']);')); |
---|
| 289 | |
---|
| 290 | return $output; |
---|
| 291 | } |
---|
| 292 | |
---|
| 293 | /** |
---|
| 294 | * Get employees from a specific category |
---|
| 295 | * @param int $categoryID The category ID |
---|
| 296 | * @param int $organizationID The organization ID |
---|
| 297 | * @return array The list o employees of that category |
---|
| 298 | * @access public |
---|
| 299 | */ |
---|
| 300 | function getCategoryEmployees($categoryID, $organizationID) |
---|
| 301 | { |
---|
| 302 | $organizationID = (int) $organizationID; |
---|
| 303 | |
---|
| 304 | /* load the employees from the area */ |
---|
| 305 | if ($categoryID == 0) |
---|
| 306 | { |
---|
| 307 | $query = "SELECT f.funcionario_id, f.organizacao_id, a.area_id, a.sigla AS area FROM funcionario f, funcionario_status s, area a WHERE (f.funcionario_status_id = s.funcionario_status_id) AND (f.area_id = a.area_id) AND (f.funcionario_categoria_id IS NULL) AND (s.exibir = ?) AND (f.organizacao_id = ?)"; |
---|
| 308 | $result = $this->db->query($query, array('S', $organizationID)); |
---|
| 309 | } |
---|
| 310 | else |
---|
| 311 | { |
---|
| 312 | $query = "SELECT f.funcionario_id, f.organizacao_id, a.area_id, a.sigla AS area FROM funcionario f, funcionario_status s, area a WHERE (f.funcionario_status_id = s.funcionario_status_id) AND (f.area_id = a.area_id) AND (f.funcionario_categoria_id = ?) AND (s.exibir = ?) AND (f.organizacao_id = ?)"; |
---|
| 313 | $result = $this->db->query($query, array((int)$categoryID, 'S', $organizationID)); |
---|
| 314 | } |
---|
| 315 | |
---|
| 316 | $employees = $result->GetArray(-1); |
---|
[2372] | 317 | $cachedLDAP = Factory::newInstance('CachedLDAP'); |
---|
[1310] | 318 | $cachedLDAP->setOperationMode($cachedLDAP->OPERATION_MODE_NORMAL); |
---|
[795] | 319 | for ($i = 0; $i < count($employees); $i++) |
---|
| 320 | { |
---|
| 321 | /* remove numeric fields */ |
---|
| 322 | for ($j = 0; $j < $result->_numOfFields; $j++) |
---|
| 323 | unset($employees[$i][$j]); |
---|
| 324 | |
---|
| 325 | $employees[$i]['cn'] = ''; |
---|
| 326 | $employees[$i]['telephoneNumber'] = ''; |
---|
| 327 | |
---|
| 328 | /* try to find the telephone number */ |
---|
| 329 | $entry = $cachedLDAP->getEntryByID($employees[$i]['funcionario_id']); |
---|
| 330 | if ($entry) |
---|
| 331 | { |
---|
| 332 | $employees[$i]['telephoneNumber'] = is_null($entry['telephonenumber']) ? '' : $entry['telephonenumber']; |
---|
| 333 | $employees[$i]['cn'] = is_null($entry['cn']) ? '' : $entry['cn'] . (is_null($entry['last_update']) ? ' <font color="red">(excluído)</font>' : ''); |
---|
| 334 | } |
---|
| 335 | } |
---|
| 336 | |
---|
| 337 | $output = array('employees' => $employees); |
---|
| 338 | return $output; |
---|
| 339 | } |
---|
| 340 | |
---|
| 341 | /** |
---|
[2085] | 342 | * Search Employee by Name |
---|
[795] | 343 | * @param int $searchTerm term to search |
---|
| 344 | * @param int $organizationID Id of organization |
---|
| 345 | * @return array employee data information |
---|
| 346 | * @access public |
---|
| 347 | */ |
---|
[2085] | 348 | function searchEmployeeByName($searchTerm, $organizationID) |
---|
[795] | 349 | { |
---|
[2085] | 350 | /* get ldap connection */ |
---|
[2533] | 351 | $ldap = &Factory::getInstance('WorkflowObjects')->getLDAP(); |
---|
[1446] | 352 | |
---|
[1465] | 353 | $searchTermExploded = explode(" ", $searchTerm); |
---|
| 354 | $fullSearch = false; |
---|
| 355 | |
---|
[2085] | 356 | if (count($searchTermExploded) > 0){ |
---|
| 357 | for ($i=1; $i<count($searchTermExploded); $i++) { |
---|
| 358 | if (strlen($searchTermExploded[$i]) > 2) { |
---|
[1465] | 359 | $fullSearch = true; |
---|
| 360 | } |
---|
| 361 | } |
---|
| 362 | |
---|
[2085] | 363 | if ($fullSearch){ |
---|
[1465] | 364 | $searchTerm = implode("*", $searchTermExploded); |
---|
| 365 | } |
---|
| 366 | } |
---|
| 367 | |
---|
[2085] | 368 | /* searching employees by name in the ldap server */ |
---|
[2372] | 369 | $list = @ldap_search($ldap, Factory::getInstance('WorkflowLDAP')->getLDAPContext(), ('(&(cn=*' . $searchTerm . '*)(phpgwaccounttype=u))'), array('uidNumber', 'cn', 'telephoneNumber')); |
---|
[795] | 370 | if ($list === false) |
---|
| 371 | return false; |
---|
| 372 | |
---|
[2085] | 373 | /* parsing ldap result */ |
---|
[795] | 374 | $entries = ldap_get_entries($ldap, $list); |
---|
[2085] | 375 | $ldapResult = array(); |
---|
| 376 | |
---|
[795] | 377 | for ($i = 0; $i < $entries['count']; $i++) |
---|
| 378 | $ldapResult[$entries[$i]['uidnumber'][0]] = array('cn' => $entries[$i]['cn'][0], 'telephoneNumber' => $entries[$i]['telephonenumber'][0]); |
---|
| 379 | |
---|
[2085] | 380 | /* no records found. bye. */ |
---|
| 381 | if (count($ldapResult) == 0) |
---|
| 382 | return array(); |
---|
| 383 | |
---|
[1446] | 384 | $uids = implode( ',', array_keys( $ldapResult ) ); |
---|
| 385 | |
---|
[2085] | 386 | /* searching for aditional employee information */ |
---|
| 387 | $query = "SELECT "; |
---|
| 388 | $query .= " f.funcionario_id AS funcionario_id, f.area_id AS area_id, a.sigla AS area "; |
---|
| 389 | $query .= " FROM "; |
---|
| 390 | $query .= " funcionario f "; |
---|
| 391 | $query .= " INNER JOIN "; |
---|
| 392 | $query .= " area a USING (area_id) "; |
---|
| 393 | $query .= " INNER JOIN "; |
---|
| 394 | $query .= " funcionario_status s ON ((f.funcionario_status_id = s.funcionario_status_id) AND (s.exibir = 'S')) "; |
---|
| 395 | $query .= " WHERE "; |
---|
| 396 | $query .= " (f.organizacao_id = ?) "; |
---|
| 397 | $query .= " AND "; |
---|
| 398 | $query .= " (f.funcionario_id IN ({$uids})) "; |
---|
[795] | 399 | |
---|
[2085] | 400 | $result = $this->db->query($query, array($organizationID))->GetArray(-1); |
---|
| 401 | $employees = array(); |
---|
[1446] | 402 | |
---|
[2085] | 403 | /* filling return array with employee's information */ |
---|
| 404 | for ($i = 0; $i < count($result); $i++) { |
---|
| 405 | $employees []= array( |
---|
| 406 | 'area' => $result[$i]['area'], |
---|
| 407 | 'area_id' => $result[$i]['area_id'], |
---|
| 408 | 'funcionario_id' => $result[$i]['funcionario_id'], |
---|
| 409 | 'cn' => $ldapResult[$result[$i]['funcionario_id']]['cn'], |
---|
| 410 | 'telephoneNumber' => empty($ldapResult[$result[$i]['funcionario_id']]['telephoneNumber']) ? '': $ldapResult[$result[$i]['funcionario_id']]['telephoneNumber'] |
---|
| 411 | ); |
---|
| 412 | } |
---|
[1446] | 413 | |
---|
[2085] | 414 | /* sorting by name (cn) */ |
---|
| 415 | $sort_function = create_function('$a, $b', 'return strcasecmp($a[\'cn\'],$b[\'cn\']);'); |
---|
| 416 | usort($employees, $sort_function ); |
---|
[1446] | 417 | |
---|
[2085] | 418 | return $employees; |
---|
| 419 | } |
---|
[1446] | 420 | |
---|
[2085] | 421 | /** |
---|
| 422 | * Search Employee by Area |
---|
| 423 | * @param int $searchTerm term to search |
---|
| 424 | * @param int $organizationID Id of organization |
---|
| 425 | * @return array employee data information |
---|
| 426 | * @access public |
---|
| 427 | */ |
---|
| 428 | function searchEmployeeByArea($searchTerm, $organizationID) |
---|
| 429 | { |
---|
| 430 | /* get ldap connection */ |
---|
[2533] | 431 | $ldap = &Factory::getInstance('WorkflowObjects')->getLDAP(); |
---|
[1446] | 432 | |
---|
[2085] | 433 | /* makes no sense search for an area if the string has more than one word */ |
---|
| 434 | if (count(explode(" ", $searchTerm)) > 1) |
---|
| 435 | return array(); |
---|
| 436 | |
---|
| 437 | /* searching for employees in areas that match 'searchTerm' */ |
---|
| 438 | $query = "SELECT "; |
---|
| 439 | $query .= " f.funcionario_id AS funcionario_id, f.area_id AS area_id, a.sigla AS area "; |
---|
| 440 | $query .= " FROM "; |
---|
| 441 | $query .= " funcionario f "; |
---|
| 442 | $query .= " INNER JOIN "; |
---|
| 443 | $query .= " area a USING (area_id) "; |
---|
| 444 | $query .= " INNER JOIN "; |
---|
| 445 | $query .= " funcionario_status s ON ((f.funcionario_status_id = s.funcionario_status_id) AND (s.exibir = 'S')) "; |
---|
| 446 | $query .= " WHERE "; |
---|
| 447 | $query .= " (f.organizacao_id = ?) "; |
---|
| 448 | $query .= " AND "; |
---|
| 449 | $query .= " (UPPER(a.sigla) LIKE UPPER(?)) "; |
---|
| 450 | |
---|
| 451 | $result = $this->db->query($query, array($organizationID, '%'.$searchTerm.'%'))->GetArray(-1); |
---|
| 452 | |
---|
| 453 | /* no records found. bye */ |
---|
| 454 | if (count($result) == 0) |
---|
| 455 | return array(); |
---|
| 456 | |
---|
| 457 | /* creating the ldap query */ |
---|
| 458 | $ldap_query = '(&(|'; |
---|
| 459 | for ($i = 0; $i < count($result); $i++) { |
---|
| 460 | $ldap_query .= '(uidNumber=' . $result[$i]['funcionario_id'] . ')'; |
---|
[795] | 461 | } |
---|
[2085] | 462 | $ldap_query .= ')(phpgwAccountType=u))'; |
---|
[795] | 463 | |
---|
[2085] | 464 | /* executing it */ |
---|
[2372] | 465 | $list = @ldap_search($ldap, Factory::getInstance('WorkflowLDAP')->getLDAPContext(), $ldap_query, array('uidNumber', 'cn', 'telephoneNumber')); |
---|
[2085] | 466 | $entries = ldap_get_entries($ldap, $list); |
---|
[1446] | 467 | |
---|
[2085] | 468 | /* parsing result */ |
---|
| 469 | $ldapResult = array(); |
---|
| 470 | for ($i = 0; $i < $entries['count']; $i++) |
---|
| 471 | $ldapResult[$entries[$i]['uidnumber'][0]] = array('cn' => $entries[$i]['cn'][0], 'telephoneNumber' => $entries[$i]['telephonenumber'][0]); |
---|
[1446] | 472 | |
---|
[2094] | 473 | /* we will need to search into database 'cache' for users deleted in ldap */ |
---|
[2372] | 474 | $cachedLDAP = Factory::newInstance( 'CachedLDAP' ); |
---|
[2094] | 475 | $cachedLDAP -> setOperationMode( $cachedLDAP -> OPERATION_MODE_DATABASE ); |
---|
| 476 | |
---|
[2085] | 477 | /* filling return array with employee's information */ |
---|
| 478 | $employees = array(); |
---|
| 479 | for ($i = 0; $i < count($result); $i++) { |
---|
[2094] | 480 | |
---|
| 481 | $employee = array(); |
---|
| 482 | |
---|
| 483 | /* user deleted in ldap. Let's try to find him into database 'cache' */ |
---|
| 484 | if (empty($ldapResult[$result[$i]['funcionario_id']]['cn'])) { |
---|
| 485 | $entry = $cachedLDAP->getEntryByID($result[$i]['funcionario_id']); |
---|
| 486 | |
---|
| 487 | $employee['removed'] = is_null($entry['last_update']); |
---|
| 488 | |
---|
| 489 | if ($entry && !empty($entry['cn'])) |
---|
| 490 | $employee['cn'] = $entry['cn']; |
---|
| 491 | /* we cant find it anywhere */ |
---|
| 492 | else |
---|
| 493 | $employee['cn'] = $result[$i]['funcionario_id']; |
---|
| 494 | } |
---|
| 495 | else |
---|
| 496 | $employee['cn'] = $ldapResult[$result[$i]['funcionario_id']]['cn']; |
---|
| 497 | |
---|
| 498 | $employee['area'] = $result[$i]['area']; |
---|
| 499 | $employee['area_id'] = $result[$i]['area_id']; |
---|
| 500 | $employee['funcionario_id'] = $result[$i]['funcionario_id']; |
---|
| 501 | $employee['telephoneNumber'] = empty($ldapResult[$result[$i]['funcionario_id']]['telephoneNumber']) ? '': $ldapResult[$result[$i]['funcionario_id']]['telephoneNumber']; |
---|
| 502 | |
---|
| 503 | $employees []= $employee; |
---|
[1446] | 504 | } |
---|
| 505 | |
---|
[2085] | 506 | /* sorting by name (cn) */ |
---|
| 507 | $sort_function = create_function('$a, $b', 'return strcasecmp($a[\'cn\'],$b[\'cn\']);'); |
---|
| 508 | usort($employees, $sort_function ); |
---|
[1446] | 509 | |
---|
[2085] | 510 | return $employees; |
---|
[795] | 511 | } |
---|
| 512 | |
---|
| 513 | /** |
---|
[2085] | 514 | * Search Employee by Telephone |
---|
| 515 | * @param int $searchTerm term to search |
---|
| 516 | * @param int $organizationID Id of organization |
---|
| 517 | * @return array employee data information |
---|
| 518 | * @access public |
---|
| 519 | */ |
---|
| 520 | function searchEmployeeByTelephone($searchTerm, $organizationID) |
---|
| 521 | { |
---|
| 522 | /* we will just excute it if we just get numbers and '-' */ |
---|
| 523 | if (!preg_match('/^[0-9-]+$/', $searchTerm)) |
---|
| 524 | return array(); |
---|
| 525 | |
---|
| 526 | /* get ldap connection */ |
---|
[2533] | 527 | $ldap = &Factory::getInstance('WorkflowObjects')->getLDAP(); |
---|
[2085] | 528 | |
---|
| 529 | /* searching employees by telephoneNumber in the ldap server */ |
---|
[2372] | 530 | $list = @ldap_search($ldap, Factory::getInstance('WorkflowLDAP')->getLDAPContext(), ('(&(telephoneNumber=*' . $searchTerm . '*)(phpgwaccounttype=u))'), array('uidNumber', 'cn', 'telephoneNumber')); |
---|
[2085] | 531 | |
---|
| 532 | if (!$list) return false; |
---|
| 533 | |
---|
| 534 | /* parsing ldap result */ |
---|
| 535 | $entries = ldap_get_entries($ldap, $list); |
---|
| 536 | $ldapResult = array(); |
---|
| 537 | |
---|
| 538 | for ($i = 0; $i < $entries['count']; $i++) |
---|
| 539 | $ldapResult[$entries[$i]['uidnumber'][0]] = array('cn' => $entries[$i]['cn'][0], 'telephoneNumber' => $entries[$i]['telephonenumber'][0]); |
---|
| 540 | |
---|
| 541 | /* no records found. bye. */ |
---|
| 542 | if (count($ldapResult) == 0) |
---|
| 543 | return array(); |
---|
| 544 | |
---|
| 545 | $uids = implode( ',', array_keys( $ldapResult ) ); |
---|
| 546 | |
---|
| 547 | /* searching for aditional employee information */ |
---|
| 548 | $query = "SELECT "; |
---|
| 549 | $query .= " f.funcionario_id AS funcionario_id, f.area_id AS area_id, a.sigla AS area "; |
---|
| 550 | $query .= " FROM "; |
---|
| 551 | $query .= " funcionario f "; |
---|
| 552 | $query .= " INNER JOIN "; |
---|
| 553 | $query .= " area a USING (area_id) "; |
---|
| 554 | $query .= " INNER JOIN "; |
---|
| 555 | $query .= " funcionario_status s ON ((f.funcionario_status_id = s.funcionario_status_id) AND (s.exibir = 'S')) "; |
---|
| 556 | $query .= " WHERE "; |
---|
| 557 | $query .= " (f.organizacao_id = ?) "; |
---|
| 558 | $query .= " AND "; |
---|
| 559 | $query .= " (f.funcionario_id IN ({$uids})) "; |
---|
| 560 | |
---|
| 561 | $result = $this->db->query($query, array($organizationID))->GetArray(-1); |
---|
| 562 | $employees = array(); |
---|
| 563 | |
---|
| 564 | /* filling return array with employee's information */ |
---|
| 565 | for ($i = 0; $i < count($result); $i++) { |
---|
| 566 | $employees []= array( |
---|
| 567 | 'area' => $result[$i]['area'], |
---|
| 568 | 'area_id' => $result[$i]['area_id'], |
---|
| 569 | 'funcionario_id' => $result[$i]['funcionario_id'], |
---|
| 570 | 'cn' => $ldapResult[$result[$i]['funcionario_id']]['cn'], |
---|
| 571 | 'telephoneNumber' => empty($ldapResult[$result[$i]['funcionario_id']]['telephoneNumber']) ? '': $ldapResult[$result[$i]['funcionario_id']]['telephoneNumber'] |
---|
| 572 | ); |
---|
| 573 | } |
---|
| 574 | |
---|
| 575 | /* sorting by name (cn) */ |
---|
| 576 | $sort_function = create_function('$a, $b', 'return strcasecmp($a[\'cn\'],$b[\'cn\']);'); |
---|
| 577 | usort($employees, $sort_function ); |
---|
| 578 | |
---|
| 579 | return $employees; |
---|
| 580 | } |
---|
| 581 | |
---|
| 582 | |
---|
| 583 | /** |
---|
[795] | 584 | * Busca informações sobre um funcionário. |
---|
| 585 | * @param array $params Uma array contendo o ID do funcionário cujas informações serão extraídas e de sua organização (Ajax). |
---|
| 586 | * @param int $employeeID O ID do funcionário. |
---|
| 587 | * @param int $organizationID O ID da organização. |
---|
| 588 | * @return array Informações sobre o funcionário. |
---|
| 589 | * @access public |
---|
| 590 | */ |
---|
| 591 | function getEmployeeInfo($employeeID, $organizationID) |
---|
| 592 | { |
---|
[2372] | 593 | $SOOrgchart = &Factory::getInstance('so_orgchart'); |
---|
[795] | 594 | $SOOrgchart->setExternalCalls(true); |
---|
| 595 | $output = $SOOrgchart->getEmployeeInfo($employeeID, $organizationID); |
---|
| 596 | $SOOrgchart->setExternalCalls(false); |
---|
| 597 | |
---|
| 598 | return $output; |
---|
| 599 | } |
---|
| 600 | |
---|
| 601 | /** |
---|
| 602 | * Busca informações sobre uma área. |
---|
| 603 | * @param array $params Uma array contendo o ID da área cujas informações serão extraídas e de sua organização (Ajax). |
---|
| 604 | * @param int $areaID O ID da área. |
---|
| 605 | * @param int $organizationID O ID da organização. |
---|
| 606 | * @return array Informações sobre a área. |
---|
| 607 | * @access public |
---|
| 608 | */ |
---|
| 609 | function getAreaInfo($areaID, $organizationID) |
---|
| 610 | { |
---|
[2372] | 611 | $SOOrgchart = &Factory::getInstance('so_orgchart'); |
---|
[795] | 612 | $SOOrgchart->setExternalCalls(true); |
---|
| 613 | $output = $SOOrgchart->getAreaInfo($areaID, $organizationID); |
---|
| 614 | $SOOrgchart->setExternalCalls(false); |
---|
| 615 | |
---|
| 616 | return $output; |
---|
| 617 | } |
---|
[1245] | 618 | |
---|
| 619 | /** |
---|
| 620 | * Get useful phones list |
---|
| 621 | * @param int $organizationID The organization ID |
---|
| 622 | * @return array Useful phones list |
---|
| 623 | * @access public |
---|
| 624 | */ |
---|
| 625 | function getUsefulPhones( $organizationID ) |
---|
| 626 | { |
---|
| 627 | $result = $this -> db -> query( "SELECT descricao, numero FROM telefone WHERE (organizacao_id = ?) ORDER BY descricao", array( $organizationID ) ); |
---|
| 628 | |
---|
| 629 | $output = $result->GetArray(-1); |
---|
| 630 | for ($i = 0; $i < count($output); $i++) |
---|
| 631 | for ($j = 0; $j < $result->_numOfFields; $j++) |
---|
| 632 | unset($output[$i][$j]); |
---|
| 633 | |
---|
| 634 | return $output; |
---|
| 635 | } |
---|
| 636 | |
---|
| 637 | /** |
---|
| 638 | * Get areas with substitute boss |
---|
| 639 | * @param int $organizationID The organization ID |
---|
| 640 | * @return array areas with substitute boss |
---|
| 641 | * @access public |
---|
| 642 | */ |
---|
| 643 | function getAreaWithSubtituteBoss( $organizationID ) |
---|
| 644 | { |
---|
[2056] | 645 | $result = $this -> db -> query( "SELECT a.sigla as area, a.titular_funcionario_id as titular, s.funcionario_id as substituto, s.data_inicio, s.data_fim FROM area a INNER JOIN substituicao s ON ((a.area_id = s.area_id) AND (CURRENT_DATE BETWEEN s.data_inicio AND s.data_fim)) WHERE (organizacao_id = ?) ORDER BY area", array( $organizationID ) ); |
---|
[1245] | 646 | |
---|
[2372] | 647 | $cachedLDAP = Factory::newInstance( 'CachedLDAP' ); |
---|
[1245] | 648 | $cachedLDAP -> setOperationMode( $cachedLDAP -> OPERATION_MODE_LDAP_DATABASE ); |
---|
| 649 | |
---|
| 650 | $output = $result->GetArray(-1); |
---|
| 651 | for ( $i = 0; $i < count($output); $i++ ) |
---|
| 652 | { |
---|
| 653 | for ($j = 0; $j < $result->_numOfFields; $j++) |
---|
| 654 | unset($output[$i][$j]); |
---|
| 655 | |
---|
| 656 | $entry = $cachedLDAP -> getEntryByID( $output[ $i ][ 'titular' ] ); |
---|
| 657 | if ( $entry && ( ! is_null( $entry[ 'cn' ] ) ) ) |
---|
| 658 | $output[ $i ][ 'titular' ] = $entry[ 'cn' ]; |
---|
| 659 | |
---|
| 660 | $entry = $cachedLDAP -> getEntryByID( $output[ $i ][ 'substituto' ] ); |
---|
| 661 | if ( $entry && ( ! is_null( $entry[ 'cn' ] ) ) ) |
---|
| 662 | $output[ $i ][ 'substituto' ] = $entry[ 'cn' ]; |
---|
[2042] | 663 | |
---|
| 664 | $output[$i]['data_inicio'] = implode('/', array_reverse(explode('-', $output[$i]['data_inicio']))); |
---|
| 665 | $output[$i]['data_fim'] = implode('/', array_reverse(explode('-', $output[$i]['data_fim']))); |
---|
[1245] | 666 | } |
---|
| 667 | |
---|
| 668 | return $output; |
---|
| 669 | } |
---|
[1266] | 670 | |
---|
| 671 | /** |
---|
| 672 | * Get manning list |
---|
| 673 | * @param int $organizationID The organization ID |
---|
| 674 | * @return array The manning list |
---|
| 675 | * @access public |
---|
| 676 | */ |
---|
| 677 | function getManning( $organizationID ) |
---|
| 678 | { |
---|
| 679 | $result = $this -> db -> query( 'SELECT localidade_id, descricao FROM localidade WHERE (organizacao_id = ?) ORDER BY descricao', array( $organizationID ) ); |
---|
| 680 | |
---|
| 681 | $output = $result->GetArray( -1 ); |
---|
| 682 | for ( $i = 0; $i < count($output); $i++ ) |
---|
| 683 | for ($j = 0; $j < $result->_numOfFields; $j++) |
---|
| 684 | unset($output[$i][$j]); |
---|
| 685 | |
---|
| 686 | return $output; |
---|
| 687 | } |
---|
| 688 | |
---|
| 689 | /** |
---|
| 690 | * Get employees from a specific location |
---|
| 691 | * @param int $categoryID The category ID |
---|
| 692 | * @param int $organizationID The organization ID |
---|
| 693 | * @return array The list o employees of that location |
---|
| 694 | * @access public |
---|
| 695 | */ |
---|
| 696 | function getManningEmployees( $locationID, $organizationID ) |
---|
| 697 | { |
---|
| 698 | $organizationID = ( int ) $organizationID; |
---|
| 699 | $locationID = ( int ) $locationID; |
---|
| 700 | |
---|
| 701 | // load the employees from the location |
---|
| 702 | $query = "SELECT f.funcionario_id, f.organizacao_id, f.area_id, a.sigla AS area," |
---|
| 703 | . " COALESCE(f.funcionario_categoria_id, 0) AS funcionario_categoria_id" |
---|
| 704 | . " FROM funcionario f, funcionario_status s, area a" |
---|
| 705 | . " WHERE (f.area_id = a.area_id)" |
---|
| 706 | . " AND (f.funcionario_status_id = s.funcionario_status_id)" |
---|
[1269] | 707 | . " AND (f.organizacao_id = ?)" |
---|
[1266] | 708 | . " AND (f.localidade_id = ?)" |
---|
| 709 | . " AND (s.exibir = ?)"; |
---|
| 710 | |
---|
[1269] | 711 | $result = $this -> db -> query( $query, array( $organizationID, $locationID, 'S' ) ); |
---|
[1266] | 712 | |
---|
| 713 | $employees = $result -> GetArray( -1 ); |
---|
[2372] | 714 | $cachedLDAP = Factory::newInstance( 'CachedLDAP' ); |
---|
[1310] | 715 | $cachedLDAP -> setOperationMode( $cachedLDAP -> OPERATION_MODE_NORMAL ); |
---|
[1266] | 716 | |
---|
| 717 | $categoriesCount = array( ); |
---|
| 718 | for ( $i = 0; $i < count( $employees ); $i++ ) |
---|
| 719 | { |
---|
| 720 | // remove numeric fields |
---|
| 721 | for ( $j = 0; $j < $result -> _numOfFields; $j++ ) |
---|
| 722 | unset( $employees[ $i ][ $j ] ); |
---|
| 723 | |
---|
| 724 | $employees[ $i ][ 'cn' ] = ''; |
---|
| 725 | $employees[ $i ][ 'telephoneNumber' ] = ''; |
---|
| 726 | |
---|
| 727 | // try to find the telephone number |
---|
| 728 | $entry = $cachedLDAP -> getEntryByID( $employees[ $i ][ 'funcionario_id' ] ); |
---|
| 729 | if ( $entry ) |
---|
| 730 | { |
---|
| 731 | $employees[ $i ][ 'telephoneNumber' ] = is_null( $entry[ 'telephonenumber' ] ) ? '' : $entry[ 'telephonenumber' ]; |
---|
| 732 | $employees[ $i ][ 'cn' ] = is_null( $entry[ 'cn' ] ) ? '' : $entry[ 'cn' ]; |
---|
| 733 | $employees[ $i ][ 'removed' ] = is_null( $entry[ 'last_update' ] ); |
---|
| 734 | } |
---|
| 735 | |
---|
| 736 | // count the number of employees in each category |
---|
| 737 | $categoryID = $employees[ $i ][ 'funcionario_categoria_id' ]; |
---|
| 738 | if ( isset( $categoriesCount[ $categoryID ] ) ) |
---|
| 739 | $categoriesCount[ $categoryID ]++; |
---|
| 740 | else |
---|
| 741 | $categoriesCount[ $categoryID ] = 1; |
---|
| 742 | } |
---|
| 743 | |
---|
| 744 | $usedCategories = array_keys( $categoriesCount ); |
---|
| 745 | $availableCategories = $this -> getCategoriesList( $organizationID ); |
---|
| 746 | $output = array( ); |
---|
| 747 | $output[ 'employees' ] = $employees; |
---|
| 748 | $output[ 'categories' ] = array( ); |
---|
| 749 | foreach ( $availableCategories as $category ) |
---|
| 750 | { |
---|
| 751 | if ( ! in_array( $category[ 'funcionario_categoria_id' ], $usedCategories ) ) |
---|
| 752 | continue; |
---|
| 753 | |
---|
| 754 | $category[ 'contagem' ] = $categoriesCount[ $category[ 'funcionario_categoria_id' ] ]; |
---|
| 755 | $output[ 'categories' ][ ] = $category; |
---|
| 756 | } |
---|
| 757 | |
---|
| 758 | usort( $output[ 'employees' ], create_function( '$a,$b', 'return strcasecmp($a[\'cn\'],$b[\'cn\']);' ) ); |
---|
| 759 | |
---|
| 760 | return $output; |
---|
| 761 | } |
---|
[1269] | 762 | |
---|
| 763 | /** |
---|
| 764 | * Return the list of employees in alphabetical order |
---|
| 765 | * @param int $organizationID The organization ID |
---|
| 766 | * @return array The list o employees |
---|
| 767 | * @access public |
---|
| 768 | */ |
---|
| 769 | function getAlphabeticalEmployees( $organizationID ) |
---|
| 770 | { |
---|
| 771 | $organizationID = ( int ) $organizationID; |
---|
| 772 | |
---|
| 773 | // load the employees from the location |
---|
| 774 | $query = "SELECT f.funcionario_id, f.organizacao_id, f.area_id, a.sigla AS area," |
---|
| 775 | . " COALESCE(f.funcionario_categoria_id, 0) AS funcionario_categoria_id" |
---|
| 776 | . " FROM funcionario f, funcionario_status s, area a" |
---|
| 777 | . " WHERE (f.area_id = a.area_id)" |
---|
| 778 | . " AND (f.funcionario_status_id = s.funcionario_status_id)" |
---|
| 779 | . " AND (f.organizacao_id = ?)" |
---|
| 780 | . " AND (s.exibir = ?)"; |
---|
| 781 | |
---|
| 782 | $result = $this -> db -> query( $query, array( $organizationID, 'S' ) ); |
---|
| 783 | |
---|
| 784 | $employees = $result -> GetArray( -1 ); |
---|
[1276] | 785 | |
---|
[2372] | 786 | $cachedLDAP = Factory::newInstance( 'CachedLDAP' ); |
---|
[1310] | 787 | $cachedLDAP -> setOperationMode( $cachedLDAP -> OPERATION_MODE_NORMAL ); |
---|
[1269] | 788 | |
---|
| 789 | $categoriesCount = array( ); |
---|
| 790 | for ( $i = 0; $i < count( $employees ); $i++ ) |
---|
| 791 | { |
---|
| 792 | // remove numeric fields |
---|
| 793 | for ( $j = 0; $j < $result -> _numOfFields; $j++ ) |
---|
| 794 | unset( $employees[ $i ][ $j ] ); |
---|
| 795 | |
---|
| 796 | $employees[ $i ][ 'cn' ] = ''; |
---|
| 797 | $employees[ $i ][ 'telephoneNumber' ] = ''; |
---|
| 798 | |
---|
| 799 | // try to find the telephone number |
---|
| 800 | $entry = $cachedLDAP -> getEntryByID( $employees[ $i ][ 'funcionario_id' ] ); |
---|
| 801 | if ( $entry ) |
---|
| 802 | { |
---|
| 803 | $employees[ $i ][ 'telephoneNumber' ] = is_null( $entry[ 'telephonenumber' ] ) ? '' : $entry[ 'telephonenumber' ]; |
---|
| 804 | $employees[ $i ][ 'cn' ] = is_null( $entry[ 'cn' ] ) ? '' : $entry[ 'cn' ]; |
---|
| 805 | $employees[ $i ][ 'removed' ] = is_null( $entry[ 'last_update' ] ); |
---|
| 806 | } |
---|
| 807 | |
---|
[1276] | 808 | } |
---|
| 809 | |
---|
| 810 | usort( $employees, create_function( '$a,$b', 'return strcasecmp($a[\'cn\'],$b[\'cn\']);' ) ); |
---|
| 811 | |
---|
[2372] | 812 | $paging = Factory::newInstance('Paging', 50, $_POST); |
---|
[1276] | 813 | $employees = $paging->restrictItems( $employees ); |
---|
| 814 | |
---|
| 815 | // count the number of employees in each category |
---|
| 816 | for ( $i = 0; $i < count( $employees ); $i++ ) |
---|
| 817 | { |
---|
[1269] | 818 | $categoryID = $employees[ $i ][ 'funcionario_categoria_id' ]; |
---|
| 819 | if ( isset( $categoriesCount[ $categoryID ] ) ) |
---|
| 820 | $categoriesCount[ $categoryID ]++; |
---|
| 821 | else |
---|
| 822 | $categoriesCount[ $categoryID ] = 1; |
---|
| 823 | } |
---|
| 824 | |
---|
| 825 | $usedCategories = array_keys( $categoriesCount ); |
---|
| 826 | $availableCategories = $this -> getCategoriesList( $organizationID ); |
---|
| 827 | $output = array( ); |
---|
[1276] | 828 | |
---|
| 829 | $output['employees'] = $employees; |
---|
| 830 | $output['categories'] = array( ); |
---|
| 831 | $output['paging_links'] = $paging -> commonLinks(); |
---|
| 832 | |
---|
[1269] | 833 | foreach ( $availableCategories as $category ) |
---|
| 834 | { |
---|
| 835 | if ( ! in_array( $category[ 'funcionario_categoria_id' ], $usedCategories ) ) |
---|
| 836 | continue; |
---|
| 837 | |
---|
| 838 | $category[ 'contagem' ] = $categoriesCount[ $category[ 'funcionario_categoria_id' ] ]; |
---|
| 839 | $output[ 'categories' ][ ] = $category; |
---|
| 840 | } |
---|
| 841 | |
---|
| 842 | return $output; |
---|
| 843 | } |
---|
[795] | 844 | } |
---|
| 845 | ?> |
---|