This commit is contained in:
Julio Cesar Laura Avendaño
2016-04-20 19:46:20 -04:00
parent f3aee9a00d
commit 4993fb2630
3 changed files with 73 additions and 71 deletions

View File

@@ -6781,6 +6781,18 @@ msgstr "Departments"
msgid "Department Name"
msgstr "Department Name"
# TRANSLATION
# LABEL/ID_DEPARTMENT_ERROR_CREATE
#: LABEL/ID_DEPARTMENT_ERROR_CREATE
msgid "Error creating department"
msgstr "Error creating department"
# TRANSLATION
# LABEL/ID_DEPARTMENT_CHECK_PARENT_DEPARTMENT
#: LABEL/ID_DEPARTMENT_CHECK_PARENT_DEPARTMENT
msgid "It's necessary to check the parent-department: {0} for the sub-department: {1}"
msgstr "It's necessary to check the parent-department: {0} for the sub-department: {1}"
# TRANSLATION
# LABEL/ID_CONFIRM_CANCEL_CASE
#: LABEL/ID_CONFIRM_CANCEL_CASE

View File

@@ -2566,6 +2566,8 @@ INSERT INTO TRANSLATION (TRN_CATEGORY,TRN_ID,TRN_LANG,TRN_VALUE,TRN_UPDATE_DATE
( 'LABEL','ID_EDIT_ROLE_TITLE','en','Edit Role','2014-01-15') ,
( 'LABEL','ID_DEPARTMENTS','en','Departments','2014-01-15') ,
( 'LABEL','ID_DEPARTMENT_NAME','en','Department Name','2014-01-15') ,
( 'LABEL','ID_DEPARTMENT_ERROR_CREATE','en','Error creating department','2014-01-15') ,
( 'LABEL','ID_DEPARTMENT_CHECK_PARENT_DEPARTMENT','en','It''s necessary to check the parent-department: {0} for the sub-department: {1}','2014-01-15') ,
( 'LABEL','ID_CONFIRM_CANCEL_CASE','en','Are you sure you want to cancel this case?','2014-01-15') ,
( 'LABEL','ID_FIRSTNAME','en','First Name','2014-01-15') ,
( 'LABEL','ID_LASTNAME','en','Last Name','2014-01-15') ,
@@ -4757,7 +4759,7 @@ INSERT INTO TRANSLATION (TRN_CATEGORY,TRN_ID,TRN_LANG,TRN_VALUE,TRN_UPDATE_DATE
( 'LABEL','ID_MAFE_b1f38dfe86f39ccbd8ab1d89b266fe25','en','- Select a starting task -','2016-03-30') ,
( 'LABEL','ID_MAFE_288aae25bc408055f50c21c991903a44','en','Asynchronous','2016-03-30') ,
( 'LABEL','ID_MAFE_2fe4167817733fec8e6ba1afddf78f1b','en','Synchronous','2016-03-30') ,
( 'LABEL','ID_MAFE_0f5ae6bbf3c2244f799acb687894378c','en','The value introduced doesn\''t have the correct format with a vallid prefix (@@, @#, @=)','2016-03-30') ,
( 'LABEL','ID_MAFE_0f5ae6bbf3c2244f799acb687894378c','en','The value introduced doesn''t have the correct format with a vallid prefix (@@, @#, @=)','2016-03-30') ,
( 'LABEL','ID_MAFE_686e697538050e4664636337cc3b834f','en','Create','2016-03-30') ,
( 'LABEL','ID_MAFE_7dce122004969d56ae2e0245cb754d35','en','Edit','2016-03-30') ,
( 'LABEL','ID_MAFE_49ee3087348e8d44e1feda1917443987','en','Name','2016-03-30') ,

View File

@@ -57,99 +57,87 @@ try {
die($json->encode($nodes));
break;
case "saveDepartments":
$depsToCheck = explode("|", $_REQUEST["departmentsDN"]);
$depsToCheck = ($_REQUEST['departmentsDN'] != '')? explode('|', $_REQUEST['departmentsDN']) : [];
$depsToCheck = array_map("urldecode", $depsToCheck);
$depsToUncheck = getDepartmentsToUncheck($depsToCheck);
$RBAC =& RBAC::getSingleton();
$authenticationSource = $RBAC->authSourcesObj->load($_REQUEST["authUid"]);
$ldapAdvanced = getLDAPAdvanceInstance($_REQUEST["authUid"]);
foreach ($depsToCheck as $departmentDN) {
$baseDN = str_replace($authenticationSource["AUTH_SOURCE_BASE_DN"], "", $departmentDN);
$ous = custom_ldap_explode_dn($departmentDN);
$currentDep = array_shift($ous);
$parentDN = implode(",", $ous);
foreach ($depsToCheck as $departmentDn) {
$departmentUid = $ldapAdvanced->getDepUidIfExistsDN($departmentDn);
//$ous = custom_ldap_explode_dn($baseDN);
//$currentDep = array_shift($ous);
foreach ($ous as $key => $val) {
$aux = explode("=", $val);
if (isset($aux[0]) && strtolower(trim($aux[0])) != "ou") {
unset($ous[$key]);
}
}
if ($currentDep == "") {
$depTitle = "ROOT " . $authenticationSource["AUTH_SOURCE_BASE_DN"];
} else {
$depAux = explode("=", $currentDep);
$depTitle = trim($depAux[1]);
}
$departmentUID = $ldapAdvanced->getDepUidIfExistsDN($departmentDN);
if ($departmentUID == "") {
if (count($ous) == 0) {
$parentUid = "";
if ($departmentUid == '') {
if (strcasecmp($departmentDn, $authenticationSource['AUTH_SOURCE_BASE_DN']) == 0) {
$departmentTitle = 'ROOT (' . $authenticationSource['AUTH_SOURCE_BASE_DN'] . ')';
$parentUid = '';
} else {
$parentUid = $ldapAdvanced->getDepUidIfExistsDN($parentDN);
$arrayAux = custom_ldap_explode_dn($departmentDn);
$departmentCurrent = array_shift($arrayAux);
$parentDn = implode(',', $arrayAux);
if ($parentUid == "") {
$response = new stdclass();
$response->status = "ERROR";
$response->message = "Parent departments are needed before create this sub department " . $parentDN;
die($json->encode($response));
$arrayAux = explode('=', $departmentCurrent);
$departmentTitle = trim($arrayAux[1]);
$parentUid = $ldapAdvanced->getDepUidIfExistsDN($parentDn);
if (str_ireplace($authenticationSource['AUTH_SOURCE_BASE_DN'], '', $parentDn) != '' &&
$parentUid == ''
) {
$response = new stdClass();
$response->status = 'ERROR';
$response->message = G::LoadTranslation(
'ID_DEPARTMENT_CHECK_PARENT_DEPARTMENT', [$parentDn, $departmentTitle]
);
echo $json->encode($response);
exit(0);
}
}
$department = new department();
$row["DEP_TITLE"] = stripslashes($depTitle);
$row["DEP_PARENT"] = $parentUid;
$row["DEP_LDAP_DN"] = $departmentDN;
$row["DEP_REF_CODE"] = "";
$departmentUID = $department->create($row);
$department = new Department();
if ($departmentUID == false) {
$response = new stdclass();
$response->status = "ERROR";
$response->message = "Error creating department";
die($json->encode($response));
$departmentUid = $department->create([
'DEP_TITLE' => stripslashes($departmentTitle),
'DEP_PARENT' => $parentUid,
'DEP_LDAP_DN' => $departmentDn,
'DEP_REF_CODE' => ''
]);
if ($departmentUid === false) {
$response = new stdClass();
$response->status = 'ERROR';
$response->message = G::LoadTranslation('ID_DEPARTMENT_ERROR_CREATE');
echo $json->encode($response);
exit(0);
}
}
}
if (count($depsToUncheck) > 0) {
foreach ($depsToUncheck as $departmentDN) {
$departmentUID = $ldapAdvanced->getDepUidIfExistsDN($departmentDN);
if (!empty($depsToUncheck)) {
$baseDnLength = strlen($authenticationSource['AUTH_SOURCE_BASE_DN']);
if ($departmentUID != "") {
$department = new department();
$departmentInfo = $department->Load($departmentUID);
foreach ($depsToUncheck as $departmentDn) {
$departmentUid = $ldapAdvanced->getDepUidIfExistsDN($departmentDn);
$arrayAux1 = custom_ldap_explode_dn($departmentDN);
if ($departmentUid != '' &&
strcasecmp(
substr($departmentDn, strlen($departmentDn) - $baseDnLength),
$authenticationSource['AUTH_SOURCE_BASE_DN']
) == 0
) {
$department = new Department();
foreach ($arrayAux1 as $index => $value) {
$arrayAux2 = explode("=", $value);
$arrayDepartmentData = $department->Load($departmentUid);
$arrayDepartmentData['DEP_LDAP_DN'] = '';
if (isset($arrayAux2[0]) && strtolower(trim($arrayAux2[0])) == "ou") {
unset($arrayAux1[$index]);
}
$result = $department->update($arrayDepartmentData);
if (!isset($authenticationSource['AUTH_SOURCE_DATA']['DEPARTMENTS_TO_UNASSIGN'])) {
$authenticationSource['AUTH_SOURCE_DATA']['DEPARTMENTS_TO_UNASSIGN'] = [];
}
$departmentBaseDn = implode(",", $arrayAux1);
if (strtolower($departmentBaseDn) == strtolower($authenticationSource["AUTH_SOURCE_BASE_DN"])) {
$departmentInfo["DEP_LDAP_DN"] = "";
$department->update($departmentInfo);
if (!isset($authenticationSource["AUTH_SOURCE_DATA"]["DEPARTMENTS_TO_UNASSIGN"])) {
$authenticationSource["AUTH_SOURCE_DATA"]["DEPARTMENTS_TO_UNASSIGN"] = array();
}
$authenticationSource["AUTH_SOURCE_DATA"]["DEPARTMENTS_TO_UNASSIGN"][] = $departmentUID;
}
$authenticationSource['AUTH_SOURCE_DATA']['DEPARTMENTS_TO_UNASSIGN'][] = $departmentUid;
}
}