query($sqlquery);
if (DB::isError($result)) die ("$PHP_SELF: " . $result->getMessage());
$insertFlag = TRUE;
while ($row = $result->fetch_assoc()):
$insertFlag = FALSE;
endwhile;
$result->free();
if ($insertFlag) :
if (checkPasswordValidation($f_usr_password,$f_usr_password2)) :
TA("B");
$sqlStmtPwd = "INSERT INTO user (hq_id,usr_type,usr_name,usr_firstname,usr_email,usr_phone,usr_phone2,usr_fax,usr_account,usr_password,usr_birthdate)" .
" VALUES ($hq_id,'$userListOfType','$f_usr_name','$f_usr_firstname','$f_usr_email','$f_usr_phone','$f_usr_phone2','$f_usr_fax','$f_usr_account',PASSWORD('$f_usr_password'),'$f_usr_birthdate')";
$res = $db->query($sqlStmtPwd);
if (DB::isError($res)) : die ("$PHP_SELF: " . $res->getMessage()); endif;
$usr_id_new = getLastInsertId();
$sqlStmtEmp = "INSERT INTO employee (usr_id,csc_id,emp_rights)" .
" VALUES ($usr_id_new,'$cscIdActual','00000000000000000000000000000000000000000000000000')";
$res = $db->query($sqlStmtEmp);
if (DB::isError($res)) : die ("$PHP_SELF: " . $res->getMessage()); endif;
$emp_id_new = getLastInsertId();
// Automatischer E-Mail-Versand eines systemgenerierten Passwortes ???
// *** Special treatment ***
if ($userListOfType == "4") :
if ($f_selectRootStock != "") :
// Insert the stock associated to the warehouseman
insertStmt("stockuser", array("stk_id", $f_selectRootStock, "usr_id", $usr_id_new));
endif;
// Set state of accessibility to substocks to readonly by default
insertStmt("parameter", array("par_key", "MASK_STK_READONLY_WHERE_DEFINED_WRITEACCESS", "emp_id", $emp_id_new, "par_value", "1", "hq_id", $hq_id));
$f_act = "setAccessRootStocks";
endif;
// Write logdata into log database
writeToLogDB("73",$hq_id,"",$usr_id,"","","","STATUS_NEW=" . $logString,"","","");
TA("C");
TA("E");
$clearUserFields = true;
endif;
else :
$statusMessage = getLngt("Der Benutzername existiert schon! Bitte wählen Sie einen anderen!");
endif;
endif;
// Modify user
if ($f_act == "modifyUser" && $usr_id_curr != "") :
// Check the user-account except the current to be modified in $usr_id_curr
$sqlquery = "SELECT usr.usr_id FROM user AS usr"
. " WHERE usr.usr_account = '" . $f_usr_account . "' AND"
. " usr.usr_id != '" . $usr_id_curr . "'";
$result = $db->query($sqlquery);
if (DB::isError($result)) die ("$PHP_SELF: " . $result->getMessage());
$updateFlag = TRUE;
while ($row = $result->fetch_assoc()):
$updateFlag = FALSE;
endwhile;
$result->free();
if ($updateFlag) :
$tmpUsrName = getFieldValueFromId("user", "usr_id", $usr_id_curr, "usr_name");
$tmpUsrFirstName = getFieldValueFromId("user", "usr_id", $usr_id_curr, "usr_firstname");
$tmpUsrAccount = getFieldValueFromId("user", "usr_id", $usr_id_curr, "usr_firstname");
$tmpUsrPassword = getFieldValueFromId("user", "usr_id", $usr_id_curr, "usr_password");
$tmpUsrBirthdate = getFieldValueFromId("user", "usr_id", $usr_id_curr, "usr_birthdate");
$tmpUsrPhone = getFieldValueFromId("user", "usr_id", $usr_id_curr, "usr_phone");
$tmpUsrPhone2 = getFieldValueFromId("user", "usr_id", $usr_id_curr, "usr_phone2");
$tmpUsrFax = getFieldValueFromId("user", "usr_id", $usr_id_curr, "usr_fax");
$logString = makeLogString(array($tmpUsrName,$tmpUsrFirstName,$tmpUsrAccount,$tmpUsrPassword,$tmpUsrBirthdate,$tmpUsrPhone,$tmpUsrPhone2,$tmpUsrFax), ";", "0");
$defaultFields = array("usr_name",$f_usr_name,"usr_firstname",$f_usr_firstname,"usr_email",$f_usr_email,"usr_phone",$f_usr_phone,"usr_phone2",$f_usr_phone2,"usr_fax",$f_usr_fax,"usr_account",$f_usr_account,"usr_birthdate",$f_usr_birthdate);
updateStmt("user","usr_id",$usr_id_curr,$defaultFields);
// *** Special treatment ***
if ($userListOfType == "4" && $f_selectRootStock != "") :
if (existsEntry("stockuser",array("usr_id",$usr_id_curr))) :
// Update the stock associated to the warehouseman
updateStmt("stockuser","usr_id",$usr_id_curr,array("stk_id",$f_selectRootStock));
else :
// Insert the stock associated to the warehouseman
insertStmt("stockuser", array("stk_id", $f_selectRootStock, "usr_id", $usr_id_curr));
endif;
$f_act = "setAccessRootStocks";
endif;
// Write logdata into log database
writeToLogDB("74",$hq_id,"",$usr_id,"","","","STATUS_MODIFIED=" . $logString,"","","");
// $clearUserFields = true;
else :
$statusMessage = getLngt("Der Benutzername existiert schon! Bitte wählen Sie einen anderen!");
endif;
endif;
// Remove user
if ($f_act == "removeUser" && $usr_id_curr != "") :
TA("B");
$tmpUsrName = getFieldValueFromId("user", "usr_id", $usr_id_curr, "usr_name");
$tmpUsrFirstName = getFieldValueFromId("user", "usr_id", $usr_id_curr, "usr_firstname");
$tmpUsrAccount = getFieldValueFromId("user", "usr_id", $usr_id_curr, "usr_firstname");
$tmpUsrPassword = getFieldValueFromId("user", "usr_id", $usr_id_curr, "usr_password");
$tmpUsrType = getFieldValueFromId("user", "usr_id", $usr_id_curr, "usr_type");
$logString = makeLogString(array($tmpUsrName,$tmpUsrFirstName,$tmpUsrAccount,$tmpEmpRigths,$tmpUsrPassword), ";", "0");
// *** Special treatment ***
if ($userListOfType == "4") :
deleteStmt("stockuser","usr_id = ".$usr_id_curr);
endif;
deleteStmt("user","usr_id = ".$usr_id_curr);
deleteStmt("employee","usr_id = ".$usr_id_curr);
// Write logdata into log database
writeToLogDB("75",$hq_id,"",$usr_id,"","","","STATUS_DELETED=" . $logString . "|TYPE=" . $tmpUsrType,"","",$usr_id_curr);
TA("C");
TA("E");
$clearUserFields = true;
endif;
// Stock employee (warehousemen)
if ($userListOfType == "4") :
// Change access to root stocks
$allRootStocksArray = getColVectorFromDB2ArrayByClause("stock", "stk_id", "stk_pre_id = '0' AND stk_path = ''", "", "");
if ($f_act == "setAccessRootStocks" && $usr_id_curr != "" && $emp_id_act != "") :
// Get the emp_id of the root admin because he/she is allowed to change a password of an employee
$empIdRootAdmin = getEmpIdOfRootAdmin($userTypeName);
if ($emp_id_act != $empIdRootAdmin) :
if ($emp_id_act != $emp_id) :
if (!is_array($par_stock_access) || $par_stock_access == "") : $par_stock_access = array(); endif;
$stkRootAccessIDsEmpIdArray = array();
$stkRootAccessIDsActEmpIdArray = array();
// Currrent user logged in
if ($emp_id == $empIdRootAdmin) :
$stkRootAccessIDsEmpIdArray = $allRootStocksArray;
$stkRootAccessIDsEmpId = implode(",", $stkRootAccessIDsEmpIdArray);
else :
$stkRootAccessIDsEmpId = getParameterValue($emp_id, "MASK_STK_ROOT_ACCESS");
if ($stkRootAccessIDsEmpId != "") :
$stkRootAccessIDsEmpIdArray = explode(",",$stkRootAccessIDsEmpId);
endif;
endif;
// Current user to be viewed or edited
$stkRootAccessIDsActEmpId = getParameterValue($emp_id_act, "MASK_STK_ROOT_ACCESS");
if ($stkRootAccessIDsActEmpId != "") :
$stkRootAccessIDsActEmpIdArray = explode(",",$stkRootAccessIDsActEmpId);
endif;
if (count($par_stock_access) > 0) :
$tmpEmpIdRestArray = array_diff($stkRootAccessIDsEmpIdArray, $par_stock_access);
$tmpEmpIdActUnionArray = array_unique(array_merge($stkRootAccessIDsActEmpIdArray, $par_stock_access));
else :
$tmpEmpIdRestArray = $stkRootAccessIDsEmpIdArray;
$tmpEmpIdActUnionArray = $stkRootAccessIDsActEmpIdArray;
endif;
$storeArray = array_diff($tmpEmpIdActUnionArray, $tmpEmpIdRestArray);
$storeString = implode(",", $storeArray);
if (existsEntry("parameter",array("par_key","MASK_STK_ROOT_ACCESS","emp_id",$emp_id_act,"hq_id",$hq_id))) :
updateStmt("parameter", "emp_id", $emp_id_act, array("par_value", $storeString), " par_key = 'MASK_STK_ROOT_ACCESS' AND hq_id = '" . $hq_id . "'");
else:
insertStmt("parameter", array("par_key", "MASK_STK_ROOT_ACCESS", "emp_id", $emp_id_act, "par_value", $storeString, "hq_id", $hq_id));
endif;
// Switch access state between readonly and writeable substocks if possible (only the changing employee is NOT readonly by himself!)
$tmpStkReadonlyEmpId = getParameterValue($emp_id, "MASK_STK_READONLY_WHERE_DEFINED_WRITEACCESS");
if ($tmpStkReadonlyEmpId == "") : $tmpStkReadonlyEmpId = "0"; endif;
if ($emp_id == $empIdRootAdmin || $tmpStkReadonlyEmpId == "0") :
if (existsEntry("parameter",array("par_key","MASK_STK_READONLY_WHERE_DEFINED_WRITEACCESS","emp_id",$emp_id_act,"hq_id",$hq_id))) :
updateStmt("parameter", "emp_id", $emp_id_act, array("par_value", $f_substocks_readonly), " par_key = 'MASK_STK_READONLY_WHERE_DEFINED_WRITEACCESS' AND hq_id = '" . $hq_id . "'");
else:
insertStmt("parameter", array("par_key", "MASK_STK_READONLY_WHERE_DEFINED_WRITEACCESS", "emp_id", $emp_id_act, "par_value", $f_substocks_readonly, "hq_id", $hq_id));
endif;
endif;
// Switch access state for article master data
$tmpStkArticleAccessEmpId = getParameterValue($emp_id, "MASK_STK_ARTICLE_ACCESS");
if ($tmpStkArticleAccessEmpId == "") : $tmpStkArticleAccessEmpId = "0"; endif;
if ($emp_id == $empIdRootAdmin || $tmpStkArticleAccessEmpId == "0") :
if (existsEntry("parameter",array("par_key","MASK_STK_ARTICLE_ACCESS","emp_id",$emp_id_act,"hq_id",$hq_id))) :
updateStmt("parameter", "emp_id", $emp_id_act, array("par_value", $f_stk_article_access), " par_key = 'MASK_STK_ARTICLE_ACCESS' AND hq_id = '" . $hq_id . "'");
else:
insertStmt("parameter", array("par_key", "MASK_STK_ARTICLE_ACCESS", "emp_id", $emp_id_act, "par_value", $f_stk_article_access, "hq_id", $hq_id, "md_id", $md_id));
endif;
endif;
else :
$statusMessage = getLngt("Ihre eigenen Lagerzugänge können Sie nicht verändern!");
endif;
else :
$statusMessage = getLngt("Sie sind leider nicht autorisiert!");
endif;
endif;
// -------------------------------------------------------------------------------------
// Right management of substocks
if ($f_act == "setAccessSubtocks" && $usr_id_curr != "" && $emp_id_act != "") :
// Get the emp_id of the root admin because he/she is allowed to change a password of an employee
$empIdRootAdmin = getEmpIdOfRootAdmin($userTypeName);
if ($emp_id_act != $empIdRootAdmin) :
if ($emp_id_act != $emp_id) :
// Get parameter of the viewed or edited emloyee to check the right for substock level
$parMaskStkSubstockActEmpIdAccess = getParameterValue($emp_id_act, "MASK_STK_SUBSTOCK_ACCESS");
// echo "PARAMETER EMP_ACT: " . $parMaskStkSubstockActEmpIdAccess . "
";
$parMaskStkSubstockActEmpIdAccess = str_replace("|", "--", $parMaskStkSubstockActEmpIdAccess);
$tmpPairsActEmpIdArray = explode("--", $parMaskStkSubstockActEmpIdAccess);
$tmpPairsActEmpIdArrayLen = count($tmpPairsActEmpIdArray);
// echo "rootStkIdForSubstkPar: " . $rootStkIdForSubstkPar . " " . getFieldValueFromId("stock","stk_id", $rootStkIdForSubstkPar,"stk_name") . "
";
// Get all HTTP-POST parameters for the substocks
if ($rootStkIdForSubstkPar > 0 && is_numeric($rootStkIdForSubstkPar)) :
$allRootStocksArray = getColVectorFromDB2ArrayByClause("stock", "stk_id", "stk_pre_id = '0' AND stk_path = ''", "", "");
list ($currStock) = getSecHttpVars("1",array("par_stock_access_subtree_" . $rootStkIdForSubstkPar));
// echo "currStock: " . $currStock . " " . getFieldValueFromId("stock","stk_id", $currStock,"stk_name") . "
";
// Check parameter being a root stock or a substock or it is empty
if ($currStock == "") :
// echo "DRIN 1
";
// Current stock is empty, no parameter change
// ...
elseif (in_array($currStock, $allRootStocksArray)) :
// echo "DRIN 2
";
// Current stock is a root stock
// Check restriction of the viewed or edited employee according to the current root stock
for ($j = 0; $j < $tmpPairsActEmpIdArrayLen; $j++) :
$tmpSubStockTupel = explode(",", $tmpPairsActEmpIdArray[$j]);
if ($tmpSubStockTupel[0] == $rootStkIdForSubstkPar) :
unset($tmpPairsActEmpIdArray[$j]);
endif;
endfor;
else :
// echo "DRIN 3
";
// Check restriction of the viewed or edited employee according to the current root stock
$tmpFound = false;
for ($j = 0; $j < $tmpPairsActEmpIdArrayLen; $j++) :
$tmpSubStockTupel = explode(",", $tmpPairsActEmpIdArray[$j]); // E.g. "3,7,4,12,26" <=> (3 = root stock, the others substocks)
if ($tmpSubStockTupel[0] == $rootStkIdForSubstkPar) :
// echo $tmpSubStockTupel[0] . " => ";
// Update ...
$newSubstockIds = $tmpSubStockTupel;
$tmpSubStockTupelLen = count($tmpSubStockTupel);
$opDone = false;
for ($k = 1; $k < $tmpSubStockTupelLen; $k++) :
if ($currStock == $tmpSubStockTupel[$k]) :
if ($rootStkOpForSubstkPar == "add") :
// It does exist, do nothing ...
$opDone = true;
endif;
if ($rootStkOpForSubstkPar == "sub") :
unset($newSubstockIds[$k]);
$opDone = true;
endif;
endif;
if (isStkChild($currStock, $tmpSubStockTupel[$k])) :
if ($rootStkOpForSubstkPar == "add") :
$newSubstockIds[$k] = $currStock;
$opDone = true;
endif;
endif;
endfor;
if (!$opDone) :
// Add new resriction
if ($rootStkOpForSubstkPar == "add") :
$newSubstockIds[] = $currStock;
endif;
endif;
// Check for removement of all substock rights but the root stock
$newSubstockIdsStr = "";
if (count($newSubstockIds) > 1) :
$newSubstockIdsStr = implode(",", $newSubstockIds);
endif;
$tmpPairsActEmpIdArray[$j] = $newSubstockIdsStr;
// echo "tmpPairsActEmpIdArray: " . $tmpPairsActEmpIdArray[$j] . "
";
$tmpFound = true;
endif;
endfor;
if (!$tmpFound) :
// Insert ...
$tmpPairsActEmpIdArray[] = $rootStkIdForSubstkPar . "," . $currStock;
endif;
endif;
// Implode updated parameter value to store
$tmpPairsActEmpId = implode("|", $tmpPairsActEmpIdArray);
if (substr($tmpPairsActEmpId, 0, 1) == "|") : $tmpPairsActEmpId = substr($tmpPairsActEmpId, 1); endif;
if (substr($tmpPairsActEmpId, -1) == "|") : $tmpPairsActEmpId = substr($tmpPairsActEmpId, 0, -1); endif;
// echo "tmpPairsActEmpId: " . $tmpPairsActEmpId . "
";
if (existsEntry("parameter",array("par_key","MASK_STK_SUBSTOCK_ACCESS","emp_id",$emp_id_act,"hq_id",$hq_id))) :
updateStmt("parameter", "emp_id", $emp_id_act, array("par_value", $tmpPairsActEmpId), " par_key = 'MASK_STK_SUBSTOCK_ACCESS' AND hq_id = '" . $hq_id . "'");
else:
insertStmt("parameter", array("par_key", "MASK_STK_SUBSTOCK_ACCESS", "emp_id", $emp_id_act, "par_value", $tmpPairsActEmpId, "hq_id", $hq_id));
endif;
endif;
else :
$statusMessage = getLngt("Ihre eigenen Lagerzugänge können Sie nicht verändern!");
endif;
else :
$statusMessage = getLngt("Sie sind leider nicht autorisiert!");
endif;
endif;
// -------------------------------------------------------------------------------------
endif;
// ***********************************************************************
// * Selection of all users of the requested user type ($userListOfType) *
// ***********************************************************************
if ($tableSort == "") : $tableSort = "usr_name"; endif;
// Stock employee (warehousemen)
if ($userListOfType == "4") :
$sqlquery = "SELECT usr.usr_id, usr.usr_name, usr.usr_firstname, usr.usr_email, usr.usr_phone,"
. " usr.usr_phone2, usr.usr_fax, usr.usr_account, hq.hq_mnemonic, emp.emp_id AS emp_id_act, par.par_value, par2.par_value AS par2_value, par3.par_value AS par3_value, par4.par_value AS par4_value"
. " FROM user AS usr, headquarters AS hq, employee AS emp LEFT JOIN parameter AS par ON par.par_key = 'MASK_STK_ROOT_ACCESS' AND par.hq_id = '" . $hq_id . "' AND par.emp_id = emp.emp_id"
. " LEFT JOIN parameter AS par2 ON par2.par_key = 'MASK_STK_SUBSTOCK_ACCESS' AND par2.hq_id = '" . $hq_id . "' AND par2.emp_id = emp.emp_id"
. " LEFT JOIN parameter AS par3 ON par3.par_key = 'MASK_STK_READONLY_WHERE_DEFINED_WRITEACCESS' AND par3.hq_id = '" . $hq_id . "' AND par3.emp_id = emp.emp_id"
. " LEFT JOIN parameter AS par4 ON par4.par_key = 'MASK_STK_ARTICLE_ACCESS' AND par4.hq_id = '" . $hq_id . "' AND par4.emp_id = emp.emp_id"
. " WHERE emp.usr_id = usr.usr_id AND usr.hq_id = hq.hq_id AND hq.hq_id IN " . getSQLMandatorArray($f_hq_id) . " AND usr.usr_type = '" . $userListOfType . "'"
. " ORDER BY $tableSort";
else :
$sqlquery = "SELECT usr.usr_id, usr.usr_name, usr.usr_firstname, usr.usr_email, usr.usr_phone,"
. " usr.usr_phone2, usr.usr_fax, usr.usr_account, hq.hq_mnemonic, emp.emp_id AS emp_id_act"
. " FROM user AS usr, headquarters AS hq, employee AS emp"
. " WHERE emp.usr_id = usr.usr_id AND usr.hq_id = hq.hq_id AND hq.hq_id IN " . getSQLMandatorArray($f_hq_id) . " AND usr.usr_type = '" . $userListOfType . "'"
. " ORDER BY $tableSort";
endif;
// echo "
" . $sqlquery . "
";
$result = $db->query($sqlquery);
if (DB::isError($result)) die ("$PHP_SELF: " . $result->getMessage());
// Maintable with header
$numOfUser = 0;
$tableOfUsers = "
| " . getLngt("Name") . " | "; $tableOfUsers .= "" . getLngt("Vorname") . " | "; if ($userTypeName == "hq" && authCheckEmployeeRights($emp_id, "10")) : $tableOfUsers .= "" . getLngt("Niederlassung") . " | "; endif; $tableOfUsers .= "" . getLngt("E-Mail") . " | "; $tableOfUsers .= "" . getLngt("Telefon") . " | "; $tableOfUsers .= "" . getLngt("Mobil") . " | "; $tableOfUsers .= "" . getLngt("Anmeldename") . " | "; $tableOfUsers .= "" . getLngt("Löschen") . " | "; $tableOfUsers .= "" . getLngt("Bearbeiten") . " | "; // endif; $tableOfUsers .= "|
| " . $row["usr_name"] . " | "; $tableOfUsers .= "" . $row["usr_firstname"] . " | "; if ($userTypeName == "hq" && authCheckEmployeeRights($emp_id, "10")) : $tableOfUsers .= "" . $row["hq_mnemonic"] . " | "; endif; $tableOfUsers .= "" . $row["usr_email"] . " | "; $tableOfUsers .= "" . $row["usr_phone"] . " | "; $tableOfUsers .= "" . $row["usr_phone2"] . " | "; $tableOfUsers .= "" . $row["usr_account"] . " | "; $tableOfUsers .= ""
. " "
. "" . " | ";
if ($userListOfType == "4") :
$currStkId = getFieldValueFromId("stockuser","usr_id",$row["usr_id"],"stk_id");
$tableOfUsers .= " " . "" . " " . "" . " | ";
else :
$tableOfUsers .= " " . "" . " " . "" . " | ";
endif;
$tableOfUsers .= "