function GetUserPermissions($CONTRACT_ID = 0, $USER_ID = false) { $err_mess = CAdvContract_all::err_mess() . "<br>Function: GetUserPermissions<br>Line: "; global $DB, $USER; static $CONTRACT_RIGHTS = array(); $USER_ID = $USER_ID === false ? intval($USER->GetID()) : intval($USER_ID); if (intval($USER_ID) <= 0) { return false; } $CONTRACT_ID = intval($CONTRACT_ID); $arrRes = array(); if ($CONTRACT_ID > 0 && is_set($CONTRACT_RIGHTS[$USER_ID], $CONTRACT_ID)) { $arrRes = $CONTRACT_RIGHTS[$USER_ID]; } else { $isManager = CAdvContract::IsManager($USER_ID); $isAdmin = CAdvContract::IsAdmin($USER_ID); if ($isAdmin) { $arrRes[0] = CAdvContract::GetMaxPermissionsArray(); } elseif ($isManager) { $arrRes[0] = array("VIEW", "ADD"); } else { $arrRes[0] = array(); } $strSqlSearch = ""; if ($CONTRACT_ID > 0) { $strSqlSearch = " and C.ID= {$CONTRACT_ID} "; } $strSql = "\n\t\t\t\tSELECT\n\t\t\t\t\tC.ID,\n\t\t\t\t\tCU.PERMISSION\n\t\t\t\tFROM\n\t\t\t\t\tb_adv_contract C\n\t\t\t\tLEFT JOIN b_adv_contract_2_user CU ON (CU.CONTRACT_ID=C.ID and CU.USER_ID={$USER_ID})\n\t\t\t\tWHERE\n\t\t\t\t\t1=1\n\t\t\t\t{$strSqlSearch}\n\t\t\t\t"; $rs = $DB->Query($strSql, false, $err_mess . __LINE__); while ($ar = $rs->Fetch()) { $arrRes[$ar["ID"]][] = $ar["PERMISSION"]; } if ($isAdmin || $isManager) { reset($arrRes); while (list($cid, $arrPerm) = each($arrRes)) { if ($isAdmin) { $arrPerm = CAdvContract::GetMaxPermissionsArray(); } elseif ($isManager) { $arrPerm[] = "VIEW"; $arrPerm[] = "ADD"; $arrPerm = array_unique($arrPerm); } $arrRes[$cid] = $arrPerm; } } reset($arrRes); while (list($cid, $arrPerm) = each($arrRes)) { TrimArr($arrPerm); $CONTRACT_RIGHTS[$USER_ID][$cid] = $arrPerm; $arrRes[$cid] = $arrPerm; } } return $arrRes; }