Changeset 3167 for branches/2.2/workflow/inc/class.so_orgchart.inc.php
- Timestamp:
- 08/17/10 16:17:12 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2/workflow/inc/class.so_orgchart.inc.php
r1446 r3167 127 127 $this->isAdmin = $_SESSION['phpgw_info']['workflow']['user_is_admin']; 128 128 $this->acl = &$GLOBALS['ajax']->acl; 129 $this->db = & $GLOBALS['workflow']['workflowObjects']->getDBWorkflow()->Link_ID;130 $this->db = & $GLOBALS['workflow']['workflowObjects']->getDBWorkflow()->Link_ID;129 $this->db = &Factory::getInstance('WorkflowObjects')->getDBWorkflow()->Link_ID; 130 $this->db = &Factory::getInstance('WorkflowObjects')->getDBWorkflow()->Link_ID; 131 131 $this->db->SetFetchMode(ADODB_FETCH_ASSOC); 132 132 } … … 699 699 $this->_checkAccess($organizationID); 700 700 701 $supervisors = '{' . implode(', ', $this->db->GetRow('SELECT COALESCE(titular_funcionario_id, -1) AS titular_funcionario_id, COALESCE(substituto_funcionario_id, -1) AS substituto_funcionario_id FROM area WHERE (area_id = ?) AND (organizacao_id = ?)', array($areaID, $organizationID))) . '}'; 701 /* gather some info from the area */ 702 $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); 703 if (empty($areaInfo)) 704 return false; 705 $areaInfo = $areaInfo[0]; 706 $supervisors = '{' . implode(', ', $areaInfo) . '}'; 707 702 708 $query = "SELECT funcionario_id, funcionario_status_id, centro_custo_id, localidade_id, organizacao_id, area_id, cargo_id, nivel, funcionario_categoria_id, titulo FROM funcionario WHERE ((area_id = ?) AND (organizacao_id = ?)) OR (funcionario_id = ANY (?))"; 703 709 $result = $this->db->query($query, array($areaID, $organizationID, $supervisors)); … … 705 711 706 712 $output = $result->GetArray(-1); 707 $cachedLDAP = $GLOBALS['workflow']['factory']->newInstance('CachedLDAP');713 $cachedLDAP = Factory::newInstance('CachedLDAP'); 708 714 $cachedLDAP->setOperationMode($cachedLDAP->OPERATION_MODE_LDAP_DATABASE); 709 715 for ($i = 0; $i < count($output); $i++) … … 711 717 $output[$i]['funcionario_id_desc'] = ''; 712 718 $output[$i]['uid'] = ''; 719 720 if (in_array($output[$i]['funcionario_id'], $areaInfo)) 721 $output[$i]['chief'] = ($output[$i]['funcionario_id'] == $areaInfo['titular_funcionario_id']) ? 1 : 2; 722 713 723 if (($entry = $cachedLDAP->getEntryByID($output[$i]['funcionario_id']))) 714 724 { … … 739 749 $unifiedResult = array(); 740 750 751 /* FIXME - this piece of code should use the new CacheLdap class */ 741 752 if (is_numeric($searchTerm)) 742 753 { … … 754 765 755 766 /* search for the $searchTerm in the LDAP */ 756 $ldap = & $GLOBALS['workflow']['workflowObjects']->getLDAP();757 $list = @ldap_search($ldap, $GLOBALS['workflow']['factory']->getInstance('WorkflowLDAP')->getLDAPContext(), $ldapSearch, array('uidnumber', 'cn', 'uid'));767 $ldap = &Factory::getInstance('WorkflowObjects')->getLDAP(); 768 $list = @ldap_search($ldap, Factory::getInstance('WorkflowLDAP')->getLDAPContext(), $ldapSearch, array('uidnumber', 'cn', 'uid')); 758 769 if ($list === false) 759 770 die(serialize("O sistema de busca não pode ser utilizado nesta organização.")); … … 763 774 764 775 /* search for the $searchTerm in the DB */ 765 $resultSet = $GLOBALS['workflow']['workflowObjects']->getDBGalaxia()->Link_ID->query($DBSearch, $DBValues)->GetArray(-1);776 $resultSet = Factory::getInstance('WorkflowObjects')->getDBGalaxia()->Link_ID->query($DBSearch, $DBValues)->GetArray(-1); 766 777 foreach ($resultSet as $row) 767 778 if (!isset($unifiedResult[$row['uidnumber']])) … … 812 823 { 813 824 $errors = array( 814 "O funcionário \"" . $GLOBALS['workflow']['factory']->getInstance('WorkflowLDAP')->getName($employeeID) . "\" já pertença à área \"{$row['sigla']}\".",825 "O funcionário \"" . Factory::getInstance('WorkflowLDAP')->getName($employeeID) . "\" já pertença à área \"{$row['sigla']}\".", 815 826 '-----------------', 816 827 'Caso você queira colocá-lo na área selecionada, siga o procedimento: faça uma busca por seu nome, clique para editá-lo e, troque pela área desejada.' … … 862 873 $this->_checkAccess($organizationID); 863 874 864 $query = 'SELECT sigla FROM area WHERE (? IN (titular_funcionario_id, substituto_funcionario_id,auxiliar_funcionario_id))';875 $query = 'SELECT DISTINCT(a.sigla) FROM area a LEFT OUTER JOIN substituicao s USING (area_id) WHERE (? IN (a.titular_funcionario_id, s.funcionario_id, a.auxiliar_funcionario_id))'; 865 876 $areas = array(); 866 877 $resultSet = $this->db->query($query, $employeeID); … … 870 881 { 871 882 $errors = array( 872 "O funcionário \"" . $GLOBALS['workflow']['factory']->getInstance('WorkflowLDAP')->getName($employeeID) . "\" é titular, substituto ouauxiliar administrativo das seguintes áreas: " . implode(", ", $areas),883 "O funcionário \"" . Factory::getInstance('WorkflowLDAP')->getName($employeeID) . "\" é titular, substituto, já participou de substituição ou é auxiliar administrativo das seguintes áreas: " . implode(", ", $areas), 873 884 '-----------------', 874 885 'Se você quiser excluir este funcionário, precisa removê-lo dos "cargos" que ele possui nas áreas citadas.' … … 890 901 * @access public 891 902 */ 892 function getArea($organizationID )903 function getArea($organizationID, $areaID = -1) 893 904 { 894 905 $this->_checkAccess($organizationID); 895 906 896 907 $output = array(); 897 898 $query = "SELECT area_id, centro_custo_id, organizacao_id, area_status_id, substituto_funcionario_id, titular_funcionario_id, superior_area_id, sigla, descricao, ativa, auxiliar_funcionario_id FROM area WHERE organizacao_id = ? ORDER BY sigla"; 899 $result = $this->db->query($query, array($organizationID)); 900 $this->_checkError($result); 901 902 $ldap = &$GLOBALS['workflow']['factory']->getInstance('WorkflowLDAP'); 908 $values = array($organizationID); 909 910 // if we are looking for a specific area 911 $area_condition = ""; 912 if (($areaID != -1) && !empty($areaID)) { 913 $area_condition = " AND a.area_id = ? "; 914 $values[]= $areaID; 915 } 916 917 $query = "SELECT a.area_id, a.centro_custo_id, a.organizacao_id, a.area_status_id, a.titular_funcionario_id, a.superior_area_id, a.sigla, a.descricao, a.ativa, a.auxiliar_funcionario_id, s.funcionario_id 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 organizacao_id = ? " . $area_condition . " ORDER BY sigla"; 918 $result = $this->db->query($query, $values); 919 $this->_checkError($result); 920 921 $ldap = &Factory::getInstance('WorkflowLDAP'); 903 922 while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC)) 904 923 { … … 958 977 * @param int $organizationID O ID da organização. 959 978 * @param int $areaStatusID O ID do status da área. 960 * @param int $backupEmployeeID O ID do funcionário que está substituindo o superior da área.961 979 * @param int $supervisorID O ID do funcionário que é superior da área. 962 980 * @param int $superiorAreaID O ID da área que é superior a que está sendo adicionada (NULL caso não possua área superior). … … 968 986 * @access public 969 987 */ 970 function addArea($costCenterID, $organizationID, $areaStatusID, $ backupEmployeeID, $supervisorID, $superiorAreaID, $acronym, $description, $active, $assistantID)971 { 972 $this->_checkAccess($organizationID); 973 974 $checkEmployees = array($ backupEmployeeID, $supervisorID, $assistantID);988 function addArea($costCenterID, $organizationID, $areaStatusID, $supervisorID, $superiorAreaID, $acronym, $description, $active, $assistantID) 989 { 990 $this->_checkAccess($organizationID); 991 992 $checkEmployees = array($supervisorID, $assistantID); 975 993 $errors = array(); 976 994 foreach ($checkEmployees as $checkEmployee) … … 981 999 $query = 'SELECT 1 FROM funcionario WHERE (funcionario_id = ?)'; 982 1000 if (!$this->db->query($query, $checkEmployee)->fetchRow()) 983 $errors[] = "O funcionário \"" . $GLOBALS['workflow']['factory']->getInstance('WorkflowLDAP')->getName($checkEmployee) . "\" não está vinculado a uma área.";1001 $errors[] = "O funcionário \"" . Factory::getInstance('WorkflowLDAP')->getName($checkEmployee) . "\" não está vinculado a uma área."; 984 1002 } 985 1003 … … 991 1009 } 992 1010 993 $query = "INSERT INTO area(centro_custo_id, organizacao_id, area_status_id, substituto_funcionario_id, titular_funcionario_id, superior_area_id, sigla, descricao, ativa, auxiliar_funcionario_id) VALUES (?,?, ?, ?, ?, ?, ?, ?, ?, ?)";994 $result = $this->db->query($query, array($costCenterID, $organizationID, $areaStatusID, $ backupEmployeeID, $supervisorID, $superiorAreaID, $acronym, $description, $active, $assistantID));1011 $query = "INSERT INTO area(centro_custo_id, organizacao_id, area_status_id, titular_funcionario_id, superior_area_id, sigla, descricao, ativa, auxiliar_funcionario_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"; 1012 $result = $this->db->query($query, array($costCenterID, $organizationID, $areaStatusID, $supervisorID, $superiorAreaID, $acronym, $description, $active, $assistantID)); 995 1013 $this->_checkError($result); 996 1014 … … 1003 1021 * @param int $organizationID O ID da organização. 1004 1022 * @param int $areaStatusID O ID do status da área. 1005 * @param int $backupEmployeeID O ID do funcionário que está substituindo o superior da área.1006 1023 * @param int $supervisorID O ID do funcionário que é superior da área. 1007 1024 * @param int $superiorAreaID O ID da área que é superior a que está sendo atualizada (NULL caso não possua área superior). … … 1014 1031 * @access public 1015 1032 */ 1016 function updateArea($costCenterID, $organizationID, $areaStatusID, $ backupEmployeeID, $supervisorID, $superiorAreaID, $acronym, $description, $active, $assistantID, $areaID)1017 { 1018 $this->_checkAccess($organizationID); 1019 1020 $checkEmployees = array($ backupEmployeeID, $supervisorID, $assistantID);1033 function updateArea($costCenterID, $organizationID, $areaStatusID, $supervisorID, $superiorAreaID, $acronym, $description, $active, $assistantID, $areaID) 1034 { 1035 $this->_checkAccess($organizationID); 1036 1037 $checkEmployees = array($supervisorID, $assistantID); 1021 1038 $errors = array(); 1022 1039 foreach ($checkEmployees as $checkEmployee) … … 1027 1044 $query = 'SELECT 1 FROM funcionario WHERE (funcionario_id = ?)'; 1028 1045 if (!$this->db->query($query, $checkEmployee)->fetchRow()) 1029 $errors[] = "O funcionário \"" . $GLOBALS['workflow']['factory']->getInstance('WorkflowLDAP')->getName($checkEmployee) . "\" não está vinculado a uma área.";1046 $errors[] = "O funcionário \"" . Factory::getInstance('WorkflowLDAP')->getName($checkEmployee) . "\" não está vinculado a uma área."; 1030 1047 } 1031 1048 … … 1033 1050 { 1034 1051 $errors[] = '-----------------'; 1035 $errors[] = 'Somente funcionários que estão vinculados a alguma área podem ser colocados na posição de titular , substitutoou auxiliar administrativo.';1052 $errors[] = 'Somente funcionários que estão vinculados a alguma área podem ser colocados na posição de titular ou auxiliar administrativo.'; 1036 1053 $this->endExecution($errors); 1037 1054 } 1038 1055 1039 $query = "UPDATE area SET centro_custo_id = ?, organizacao_id = ?, area_status_id = ?, substituto_funcionario_id = ?,titular_funcionario_id = ?, superior_area_id = ?, sigla = ?, descricao = ?, ativa = ?, auxiliar_funcionario_id = ? WHERE (area_id = ?)";1040 $result = $this->db->query($query, array($costCenterID, $organizationID, $areaStatusID, $ backupEmployeeID, $supervisorID, $superiorAreaID, $acronym, $description, $active, $assistantID, $areaID));1056 $query = "UPDATE area SET centro_custo_id = ?, organizacao_id = ?, area_status_id = ?, titular_funcionario_id = ?, superior_area_id = ?, sigla = ?, descricao = ?, ativa = ?, auxiliar_funcionario_id = ? WHERE (area_id = ?)"; 1057 $result = $this->db->query($query, array($costCenterID, $organizationID, $areaStatusID, $supervisorID, $superiorAreaID, $acronym, $description, $active, $assistantID, $areaID)); 1041 1058 $this->_checkError($result); 1042 1059 … … 1074 1091 $this->_checkAccess($organizationID, false, true); 1075 1092 1093 /** 1094 * This is so wrong.. We should always use the factory to 1095 * instantiate stuff. Besides, module class should not 1096 * use process classes; the correct is to do the inverse. 1097 */ 1076 1098 require_once dirname(__FILE__) . '/local/classes/class.wf_orgchart.php'; 1077 1099 $orgchart = new wf_orgchart(); … … 1079 1101 $outputInfo = array(); 1080 1102 1081 $cachedLDAP = $GLOBALS['workflow']['factory']->newInstance('CachedLDAP'); 1103 $cachedLDAP = Factory::newInstance('CachedLDAP'); 1104 1105 /* here we need fresh information. Let's access ldap first */ 1082 1106 $cachedLDAP->setOperationMode($cachedLDAP->OPERATION_MODE_LDAP_DATABASE); 1083 1107 $employeeEntry = $cachedLDAP->getEntryByID($employeeID); … … 1243 1267 ); 1244 1268 1245 $cachedLDAP = $GLOBALS['workflow']['factory']->newInstance('CachedLDAP');1269 $cachedLDAP = Factory::newInstance('CachedLDAP'); 1246 1270 $cachedLDAP->setOperationMode($cachedLDAP->OPERATION_MODE_LDAP_DATABASE); 1247 1271 if (!empty($areaInfo['titular_funcionario_id'])) … … 1357 1381 return ( ( $result === false ) ? false : true ); 1358 1382 } 1383 1384 /** 1385 * Validate start and end dates for a substitution 1386 * @param int $areaID Area's ID. 1387 * @param string $date_start Substitution's start date. 1388 * @param string $date_start Substitution's end date. 1389 * @return bool 1390 * @access private 1391 */ 1392 function validateSubstitutionDates($areaID, $date_start, $date_end, $substitutionID = -1) 1393 { 1394 /* TODO 1395 * I'm not supose to be here.. (date validations speaking) 1396 * move me to some validation class! 1397 */ 1398 1399 /* validating dates */ 1400 $date_pattern = '/^(0[1-9]|[12][0-9]|3[01])\/(0[1-9]|1[0-2])\/[12][0-9]{3}$/'; 1401 1402 if (!preg_match($date_pattern, $date_start)) 1403 $this->endExecution("Formato inválido para data de início."); 1404 if (!preg_match($date_pattern, $date_end)) 1405 $this->endExecution("Formato inválido para data de término. "); 1406 1407 $date_start_arr = explode('/', $date_start); 1408 $date_end_arr = explode('/', $date_end); 1409 1410 /* is it a gregorian date? */ 1411 if (!checkdate($date_start_arr[1], $date_start_arr[0], $date_start_arr[2])) 1412 $this->endExecution("Data de início inválida."); 1413 if (!checkdate($date_end_arr[1], $date_end_arr[0], $date_end_arr[2])) 1414 $this->endExecution("Data de término inválida. "); 1415 1416 /* is date_end greater then date_start? */ 1417 if (mktime(0,0,0, $date_start_arr[1], $date_start_arr[0], $date_start_arr[2]) >= mktime(0,0,0, $date_end_arr[1], $date_end_arr[0], $date_end_arr[2])) 1418 $this->endExecution("A data de término deve ser maior que a data de início."); 1419 1420 /* preparing dates to database */ 1421 $date_start = implode('-', array_reverse($date_start_arr)); 1422 $date_end = implode('-', array_reverse($date_end_arr)); 1423 1424 /* checking if there is a substitution in conflict with these dates */ 1425 $query = "SELECT * FROM substituicao WHERE "; 1426 $query .= " area_id = ? "; 1427 $query .= " AND "; 1428 $query .= " substituicao_id != ? "; 1429 $query .= " AND "; 1430 $query .= " ("; 1431 $query .= " (? BETWEEN data_inicio AND data_fim) "; 1432 $query .= " OR "; 1433 $query .= " (? BETWEEN data_inicio AND data_fim)"; 1434 $query .= " OR "; 1435 $query .= " (data_inicio BETWEEN ? AND ?)"; 1436 $query .= " ) "; 1437 1438 // raise an error if there is any record 1439 if ($row = $this->db->query($query, array( $areaID, $substitutionID, $date_start, $date_end, $date_start, $date_end ))->fetchRow()) 1440 { 1441 $row['data_inicio'] = implode('/', array_reverse(explode('-', $row['data_inicio']))); 1442 $row['data_fim'] = implode('/', array_reverse(explode('-', $row['data_fim']))); 1443 $this->endExecution('Já existe uma substituição no período de '. $row['data_inicio'] . ' a ' . $row['data_fim']); 1444 } 1445 return true; 1446 } 1447 1448 /** 1449 * Add a substitution. 1450 * @param int $organizationID Organization's ID. 1451 * @param int $areaID Area's ID. 1452 * @param int $substituteID Substitute's employee ID. 1453 * @param string $date_start Substitution's start date. 1454 * @param string $date_start Substitution's end date. 1455 * @return bool 1456 * @access public 1457 */ 1458 function addSubstitution( $organizationID, $areaID, $substituteID, $date_start, $date_end ) 1459 { 1460 $this->_checkAccess( $organizationID ); 1461 1462 if (!$this->validateSubstitutionDates($areaID, $date_start, $date_end)) 1463 return false; 1464 1465 /* formating dates */ 1466 $date_start = implode('-', array_reverse(explode('/', $date_start))); 1467 $date_end = implode('-', array_reverse(explode('/', $date_end))); 1468 1469 $query = "INSERT INTO substituicao (area_id, funcionario_id, data_inicio, data_fim) VALUES (?, ?, ?, ?)"; 1470 $result = $this -> db -> query( $query, array( $areaID, $substituteID, $date_start, $date_end ) ); 1471 $this->_checkError( $result ); 1472 1473 return ( ( $result === false ) ? false : true ); 1474 } 1475 1476 /** 1477 * Update a substitution. 1478 * @param int $organizationID Organization's ID. 1479 * @param int $areaID Area's ID. 1480 * @param int $substituteID Substitute's employee ID. 1481 * @param string $date_start Substitution's start date. 1482 * @param string $date_start Substitution's end date. 1483 * @return bool 1484 * @access public 1485 */ 1486 function updateSubstitution( $organizationID, $areaID, $substituteID, $date_start, $date_end, $substitutionID ) 1487 { 1488 $this->_checkAccess( $organizationID ); 1489 1490 if (!$this->validateSubstitutionDates($areaID, $date_start, $date_end, $substitutionID)) 1491 return false; 1492 1493 /* formating dates */ 1494 $date_start = implode('-', array_reverse(explode('/', $date_start))); 1495 $date_end = implode('-', array_reverse(explode('/', $date_end))); 1496 1497 $query = "UPDATE substituicao SET funcionario_id = ?, data_inicio = ?, data_fim = ? WHERE substituicao_id = ?"; 1498 $result = $this -> db -> query( $query, array( $substituteID, $date_start, $date_end, $substitutionID ) ); 1499 $this->_checkError( $result ); 1500 1501 return ( ( $result === false ) ? false : true ); 1502 } 1503 1504 /** 1505 * List all the substituions for a given area 1506 * @return array List of the substitutions 1507 * @access public 1508 */ 1509 function getSubstitutions( $organizationID, $areaID ) 1510 { 1511 $this -> _checkAccess( $organizationID ); 1512 1513 /* we must join area table to get organizacao_id */ 1514 $query = "SELECT s.*, a.organizacao_id FROM substituicao s INNER JOIN area a USING(area_id) WHERE area_id = ? ORDER BY data_inicio DESC"; 1515 $result = $this -> db -> query( $query, array( $areaID ) ); 1516 $this -> _checkError( $result ); 1517 1518 /* we must query ldap to get full user names. In workflow db we just store uids */ 1519 $cachedLDAP = Factory::getInstance('CachedLDAP'); 1520 1521 $output = $result->GetArray(-1); 1522 for ($i = 0; $i < count($output); $i++) { 1523 for ($j = 0; $j < $result->_numOfFields; $j++) 1524 unset($output[$i][$j]); 1525 1526 /* including substitute full name */ 1527 $ldap_result = $cachedLDAP->getEntryByID($output[$i]['funcionario_id']); 1528 $output[$i]['substituto_funcionario_id'] = $output[$i]['funcionario_id']; 1529 $output[$i]['substituto_funcionario_id_desc'] = $ldap_result['cn']; 1530 1531 /* formating dates */ 1532 $output[$i]['data_inicio'] = implode('/', array_reverse(explode('-', $output[$i]['data_inicio']))); 1533 $output[$i]['data_fim'] = implode('/', array_reverse(explode('-', $output[$i]['data_fim']))); 1534 } 1535 return $output; 1536 } 1537 1538 /** 1539 * Remove a substitution 1540 * @param int $organizationID Organization's ID 1541 * @param int $telephoneID Substitution's ID 1542 * @return bool 1543 * @access public 1544 */ 1545 function removeSubstitution( $organizationID, $substitutionID ) 1546 { 1547 $this->_checkAccess( $organizationID ); 1548 1549 $query = "DELETE FROM substituicao WHERE substituicao_id = ?"; 1550 $result = $this -> db -> query( $query, array( $substitutionID ) ); 1551 $this -> _checkError( $result ); 1552 1553 return ( ( $result === false ) ? false : true ); 1554 } 1359 1555 } 1360 1556 ?>
Note: See TracChangeset
for help on using the changeset viewer.