|
|
@@ -35,12 +35,12 @@ class access
|
|
|
|
|
|
db::query("SELECT "
|
|
|
. "" . DB_T_ACCESS . ".id, "
|
|
|
+ . "" . DB_T_ACCESS . ".label, "
|
|
|
. "" . DB_T_ACCESS . ".access, "
|
|
|
. "" . DB_T_ACCESS . ".noAccess, "
|
|
|
- . "" . DB_T_ACCESS_EXCEPTION . ".exception "
|
|
|
+ . "" . DB_T_TYPE_ACCESS . ".exception "
|
|
|
. "FROM " . DB_T_TYPE_ACCESS . " "
|
|
|
. "INNER JOIN " . DB_T_ACCESS . " ON " . DB_T_TYPE_ACCESS . ".id_access = " . DB_T_ACCESS . ".id "
|
|
|
- . "LEFT JOIN " . DB_T_ACCESS_EXCEPTION . " ON " . DB_T_TYPE_ACCESS . ".id_exception = " . DB_T_ACCESS_EXCEPTION . ".id "
|
|
|
. "WHERE " . DB_T_TYPE_ACCESS . ".id_type = :id_type ");
|
|
|
db::bind(':id_type', $idType);
|
|
|
|
|
|
@@ -61,9 +61,51 @@ class access
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public static function getAccessByType()
|
|
|
+ {
|
|
|
+ $return = array();
|
|
|
+ db::query("SELECT "
|
|
|
+ . "" . DB_T_TYPE_USER . ".type, "
|
|
|
+ . "" . DB_T_ACCESS . ".label, "
|
|
|
+ . "" . DB_T_ACCESS . ".show, "
|
|
|
+ . "" . DB_T_ACCESS . ".add "
|
|
|
+ . "FROM " . DB_T_ACCESS . " "
|
|
|
+ . "INNER JOIN " . DB_T_TYPE_USER . " ON " . DB_T_TYPE_USER . ".id = " . DB_T_TYPE_ACCESS . ".id_type "
|
|
|
+ . "INNER JOIN " . DB_T_TYPE_ACCESS . " ON " . DB_T_ACCESS . ".id = " . DB_T_TYPE_ACCESS . ".id_access");
|
|
|
+ try {
|
|
|
+ $tmp = db::resultset();
|
|
|
+
|
|
|
+ foreach ($tmp as $access) {
|
|
|
+ $return[$access["type"]][$access["label"]] = array(
|
|
|
+ "show" => $access["show"],
|
|
|
+ "add" => $access["add"],
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ return $return;
|
|
|
+ } catch (Exception $e) {
|
|
|
+ return FALSE;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static function getTypesAccess()
|
|
|
+ {
|
|
|
+ db::query("SELECT "
|
|
|
+ . "" . DB_T_ACCESS . ".label, "
|
|
|
+ . "" . DB_T_ACCESS . ".show, "
|
|
|
+ . "" . DB_T_ACCESS . ".add "
|
|
|
+ . "FROM " . DB_T_ACCESS);
|
|
|
+ try {
|
|
|
+ $tmp = db::resultset();
|
|
|
+ return $tmp;
|
|
|
+ } catch (Exception $e) {
|
|
|
+ return FALSE;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public static function getTypesUsers(bool $_expect = FALSE)
|
|
|
{
|
|
|
- $except = ($_expect == FALSE) ? NULL : " WHERE " . DB_T_TYPE_USER . ".id != 2"; // Sauf les contrôleurs
|
|
|
+ $except = ($_expect == FALSE) ? NULL : " WHERE " . DB_T_TYPE_USER . ".id != 1 AND " . DB_T_TYPE_USER . ".id != 2";
|
|
|
|
|
|
db::query("SELECT * FROM " . DB_T_TYPE_USER . $except);
|
|
|
try {
|
|
|
@@ -74,6 +116,62 @@ class access
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public static function getArrayTypes()
|
|
|
+ {
|
|
|
+ $return = $final = array();
|
|
|
+ $getTypesUsers = self::getTypesUsers(TRUE);
|
|
|
+
|
|
|
+ db::query("SELECT "
|
|
|
+ . "CONCAT(" . DB_T_ACCESS . ".label, '|', " . DB_T_ACCESS . ".show, " . DB_T_ACCESS . ".add) AS access, "
|
|
|
+ . "" . DB_T_TYPE_ACCESS . ".id_type, "
|
|
|
+ . "" . DB_T_TYPE_ACCESS . ".exception, "
|
|
|
+ . "" . DB_T_TYPE_USER . ".type "
|
|
|
+ . "FROM " . DB_T_ACCESS . " "
|
|
|
+ . "LEFT JOIN " . DB_T_TYPE_ACCESS . " ON " . DB_T_TYPE_ACCESS . ".id_access = " . DB_T_ACCESS . ".id "
|
|
|
+ . "LEFT JOIN " . DB_T_TYPE_USER . " ON " . DB_T_TYPE_ACCESS . ".id_type = " . DB_T_TYPE_USER . ".id "
|
|
|
+ );
|
|
|
+
|
|
|
+ try {
|
|
|
+ $tmp = db::resultset();
|
|
|
+
|
|
|
+ foreach ($tmp as $access) {
|
|
|
+
|
|
|
+ $tmpaccess = explode("|", $access["access"]);
|
|
|
+
|
|
|
+ if($tmpaccess[1] == "10"){
|
|
|
+ $return[$access["access"]]["access"] = "Accès à " . $tmpaccess[0] . " en lecture";
|
|
|
+ } elseif($tmpaccess[1] == "01"){
|
|
|
+ $return[$access["access"]]["access"] = "Accès à " . $tmpaccess[0] . " en écriture";
|
|
|
+ } else {
|
|
|
+ $return[$access["access"]]["access"] = "Accès à " . $tmpaccess[0] . " en lecture et écriture";
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach ($getTypesUsers as $type) {
|
|
|
+ if (empty($return[$access["access"]][$type["type"]])) {
|
|
|
+ if ($type["id"] == $access["id_type"]) {
|
|
|
+ if(is_null($access["exception"])){
|
|
|
+ $return[$access["access"]][$type["type"]] = 1;
|
|
|
+ } else {
|
|
|
+ $return[$access["access"]][$type["type"]] = 2;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ $return[$access["access"]][$type["type"]] = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $return[$access["access"]]["Administrateur"] = 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach ($return as $value) {
|
|
|
+ $final[] = $value;
|
|
|
+ }
|
|
|
+ return $final;
|
|
|
+ } catch (Exception $e) {
|
|
|
+ return FALSE;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public static function ifLimitAccessException(string $_exception)
|
|
|
{
|
|
|
$accessList = self::getAccessList(session::getType());
|
|
|
@@ -112,6 +210,11 @@ class access
|
|
|
return ($check == TRUE) ? $string : FALSE;
|
|
|
}
|
|
|
|
|
|
+ private static function getGenericAccess(string $_string)
|
|
|
+ {
|
|
|
+ return explode("*", $_string);
|
|
|
+ }
|
|
|
+
|
|
|
private static function splitAccess(string $_string)
|
|
|
{
|
|
|
$return = array();
|
|
|
@@ -126,249 +229,4 @@ class access
|
|
|
{
|
|
|
return array_unique(array_merge(self::splitAccess($_string), $_array));
|
|
|
}
|
|
|
-
|
|
|
- public static function getListTypeUser(?array $_idExceptions = NULL )
|
|
|
- {
|
|
|
- $return = array();
|
|
|
- db::query("SELECT id, type FROM " . DB_T_TYPE_USER);
|
|
|
- try {
|
|
|
- $return = [];
|
|
|
- foreach (db::resultset() as $value) {
|
|
|
- if(is_null($_idExceptions) OR (!is_null($_idExceptions) AND !in_array($value["id"], $_idExceptions)) ){
|
|
|
- $return[$value["id"]] = $value["type"];
|
|
|
- }
|
|
|
- }
|
|
|
- return $return;
|
|
|
- } catch (Exception $e) {
|
|
|
- return FALSE;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public static function printRenderAccessRow(array $valueAccess){
|
|
|
- if (!is_null($valueAccess["exception"])) {
|
|
|
- $tooltip = '<span class="ms-2" data-bs-toggle="tooltip" title="Possibilité d\'accès partiel avec les éléments cachés suivants : ' . htmlspecialchars($valueAccess["exception"]) . '"><i class="bi bi-info-circle-fill" style="color:#ffc107;"></i></span>';
|
|
|
- } else {
|
|
|
- $tooltip = '';
|
|
|
- }
|
|
|
-
|
|
|
- echo '<tr>';
|
|
|
- echo '<td style="vertical-align: middle; box-sizing: border-box;">' . $valueAccess["label"] . $tooltip . '</td>';
|
|
|
-
|
|
|
- $tmp = [];
|
|
|
-
|
|
|
- foreach ($valueAccess["access"] as $keyRole => $valueRole) {
|
|
|
- $tmp[$keyRole] = '<td style="width: 180px;"><div style="text-align:center;">';
|
|
|
- $tmp[$keyRole] .= self::getSelectAccess($valueAccess["access"][$keyRole], $valueAccess["exception"]);
|
|
|
- $tmp[$keyRole] .= '</div></td>';
|
|
|
- }
|
|
|
-
|
|
|
- echo $tmp[1]; // Administrateur
|
|
|
- echo $tmp[5]; // Bureau du CSE
|
|
|
- echo $tmp[6]; // Elu du CSE
|
|
|
- echo $tmp[7]; // Comptable
|
|
|
- echo $tmp[4]; // Modérateur du CMS
|
|
|
- echo $tmp[3]; // Assistance sociale
|
|
|
-
|
|
|
- echo '</tr>';
|
|
|
- }
|
|
|
-
|
|
|
- private static function getSelectAccess(?array $_access = NULL, ?string $_exception = NULL){
|
|
|
- if (!is_null($_exception)) {
|
|
|
- $options = [
|
|
|
- 1 => 'Autorisé',
|
|
|
- 0 => '-',
|
|
|
- 2 => 'Partiellement'
|
|
|
- ];
|
|
|
-
|
|
|
- } else {
|
|
|
- $options = [
|
|
|
- 1 => 'Autorisé',
|
|
|
- 0 => '-',
|
|
|
- ];
|
|
|
- }
|
|
|
-
|
|
|
- $bgColors = [
|
|
|
- 1 => 'background-color:#d4edda;',
|
|
|
- 0 => 'background-color:#f8d7da;',
|
|
|
- 2 => 'background-color:#ffeeba;'
|
|
|
- ];
|
|
|
-
|
|
|
- $disabled = ($_access["id_type"] == 1 OR $_access["id_access"] == 3) ? ' disabled' : '';
|
|
|
- $disabledStyle = ($_access["id_type"] == 1 OR $_access["id_access"] == 3) ? ' opacity: 0.5; cursor: not-allowed;' : '';
|
|
|
- $style = isset($bgColors[$_access["access"]]) ? $bgColors[$_access["access"]] : '';
|
|
|
-
|
|
|
- $return = '<select class="form-select form-select-sm" name="access-' . str_replace("#", "-", $_access["id_type_access"]) . '" style="' . $style . $disabledStyle . '"' . $disabled . '>';
|
|
|
- foreach ($options as $value => $label) {
|
|
|
- $selected = ($_access["access"] === $value) ? ' selected' : '';
|
|
|
- $return .= '<option value="' . $value . '"' . $selected . '>' . $label . '</option>';
|
|
|
- }
|
|
|
- $return .= '</select>';
|
|
|
-
|
|
|
- return $return;
|
|
|
- }
|
|
|
-
|
|
|
- private static function completeIdemAccess(?array $_access = NULL, string $_idAccess){
|
|
|
- $roles = self::getListTypeUser([2]); // Tous les types sauf les contrôleurs
|
|
|
- foreach ($roles as $keyRole => $valueRole) {
|
|
|
- if(empty($_access["access"][$keyRole])){
|
|
|
- $tmp = [];
|
|
|
- $tmp["id_type_access"] = $keyRole . "#" . $_access["id_access"];
|
|
|
- $tmp["id_type"] = $keyRole;
|
|
|
- $tmp["id_access"] = $_idAccess;
|
|
|
- $tmp["type"] = $valueRole;
|
|
|
- $tmp["access"] = ($keyRole == 1) ? 1 : 0;
|
|
|
- $return[$keyRole] = $tmp;
|
|
|
- } else {
|
|
|
- $return[$keyRole] = $_access["access"][$keyRole];
|
|
|
- }
|
|
|
- }
|
|
|
- return $return;
|
|
|
- }
|
|
|
-
|
|
|
- public static function finalCompletAccess(){
|
|
|
- $access = access::getTypesAccessRecording();
|
|
|
- $return = [];
|
|
|
- foreach ($access as $keyAccess => $valueAccess) {
|
|
|
- $completeAccess = access::completeIdemAccess($valueAccess, $valueAccess["id_access"]);
|
|
|
- unset($valueAccess["access"]);
|
|
|
- $valueAccess["access"] = $completeAccess;
|
|
|
- $return[] = $valueAccess;
|
|
|
- }
|
|
|
- return $return;
|
|
|
- }
|
|
|
-
|
|
|
- private static function getTypesAccess(){
|
|
|
- db::query("SELECT "
|
|
|
- . DB_T_ACCESS . ".id, "
|
|
|
- . DB_T_ACCESS . ".label, "
|
|
|
- . DB_T_ACCESS . ".show, "
|
|
|
- . DB_T_ACCESS . ".add, "
|
|
|
- . DB_T_TYPE_ACCESS . ".id AS id_type_access, "
|
|
|
- . DB_T_TYPE_ACCESS . ".id_type, "
|
|
|
- . "exception1.exception AS exception_type, "
|
|
|
- . "exception2.exception AS exception, "
|
|
|
- . DB_T_TYPE_USER . ".type "
|
|
|
- . "FROM " . DB_T_ACCESS . " "
|
|
|
- . "LEFT JOIN " . DB_T_ACCESS_EXCEPTION . " AS exception1 ON exception1.id_access = " . DB_T_ACCESS . ".id "
|
|
|
- . "LEFT JOIN " . DB_T_TYPE_ACCESS . " ON " . DB_T_TYPE_ACCESS . ".id_access = " . DB_T_ACCESS . ".id "
|
|
|
- . "LEFT JOIN " . DB_T_TYPE_USER . " ON " . DB_T_TYPE_ACCESS . ".id_type = " . DB_T_TYPE_USER . ".id "
|
|
|
- . "LEFT JOIN " . DB_T_ACCESS_EXCEPTION . " AS exception2 ON " . DB_T_TYPE_ACCESS . ".id_exception = exception2.id "
|
|
|
- );
|
|
|
- try {
|
|
|
- $tmp = db::resultset();
|
|
|
- return $tmp;
|
|
|
- } catch (Exception $e) {
|
|
|
- return FALSE;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private static function getTitleLabel(array $_array){
|
|
|
- if ($_array["show"] == 1 AND $_array["add"] == 0) {
|
|
|
- return "Accès à <strong>" . $_array["label"] . "</strong> en lecture";
|
|
|
- } elseif ($_array["show"] == 0 AND $_array["add"] == 1) {
|
|
|
- return "Accès à <strong>" . $_array["label"] . "</strong> en écriture";
|
|
|
- } else {
|
|
|
- return "Accès à <strong>" . $_array["label"] . "</strong> en lecture et écriture";
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public static function getTypesAccessRecording(){
|
|
|
- $return = [];
|
|
|
- foreach (self::getTypesAccess() as $valueAccess) {
|
|
|
- $return[$valueAccess["id"]]["id_access"] = $valueAccess["id"];
|
|
|
- $return[$valueAccess["id"]]["label"] = self::getTitleLabel($valueAccess);
|
|
|
- $return[$valueAccess["id"]]["show"] = $valueAccess["show"];
|
|
|
- $return[$valueAccess["id"]]["add"] = $valueAccess["add"];
|
|
|
- $return[$valueAccess["id"]]["exception"] = $valueAccess["exception_type"];
|
|
|
-
|
|
|
- if(!empty($valueAccess["id_type_access"])) {
|
|
|
- $return[$valueAccess["id"]]["access"][$valueAccess["id_type"]] = [
|
|
|
- "id_type_access" => $valueAccess["id_type_access"],
|
|
|
- "id_type" => $valueAccess["id_type"],
|
|
|
- "id_access" => $valueAccess["id"],
|
|
|
- "type" => $valueAccess["type"],
|
|
|
- "access" => (empty($valueAccess["exception"])) ? 1 : 2,
|
|
|
- ];
|
|
|
- }
|
|
|
- }
|
|
|
- return $return;
|
|
|
- }
|
|
|
-
|
|
|
- public static function getAccessByRole(){
|
|
|
- $getAccessByRole = self::getTypesAccessRecording();
|
|
|
- $allTypeRole = self::getTypesUsers();
|
|
|
- $return = [];
|
|
|
- foreach ($getAccessByRole as $valuesGetAccessByRole) {
|
|
|
- $tmp = [];
|
|
|
- $tmp["access"] = $valuesGetAccessByRole["label"];
|
|
|
- $tmp["exception"] = $valuesGetAccessByRole["exception"];
|
|
|
- foreach ($allTypeRole as $valueAllTypeRole) {
|
|
|
- if(!empty($valuesGetAccessByRole["access"][$valueAllTypeRole["id"]])){
|
|
|
- $tmp[$valuesGetAccessByRole["access"][$valueAllTypeRole["id"]]["type"]] = $valuesGetAccessByRole["access"][$valueAllTypeRole["id"]]["access"];
|
|
|
- } elseif($valueAllTypeRole["id"] == 1){
|
|
|
- $tmp[$valueAllTypeRole["type"]] = 1;
|
|
|
- } else {
|
|
|
- $tmp[$valueAllTypeRole["type"]] = 0;
|
|
|
- }
|
|
|
- }
|
|
|
- $return[] = $tmp;
|
|
|
- }
|
|
|
- return $return;
|
|
|
- }
|
|
|
-
|
|
|
- private static function getIdException(int $_idAccess){
|
|
|
- db::query("SELECT "
|
|
|
- . DB_T_ACCESS_EXCEPTION . ".id, "
|
|
|
- . DB_T_ACCESS_EXCEPTION . ".exception "
|
|
|
- . "FROM " . DB_T_ACCESS_EXCEPTION . " "
|
|
|
- . "WHERE " . DB_T_ACCESS_EXCEPTION . ".id_access = :id_access");
|
|
|
- db::bind(':id_access', $_idAccess);
|
|
|
- try {
|
|
|
- $tmp = db::single();
|
|
|
- return $tmp;
|
|
|
- } catch (Exception $e) {
|
|
|
- return FALSE;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public static function recordAccess(){
|
|
|
- $post = core::getPost();
|
|
|
- $data = [];
|
|
|
- foreach ($post as $keyPost => $valuePost) {
|
|
|
- if($valuePost == 1 OR $valuePost == 2){
|
|
|
- $tmp = explode("-", $keyPost);
|
|
|
- $data[$tmp[1] . "#" . $tmp[2]]["id_access"] = $tmp[2];
|
|
|
- $data[$tmp[1] . "#" . $tmp[2]]["id_type"] = $tmp[1];
|
|
|
- if($valuePost == 2){
|
|
|
- $data[$tmp[1] . "#" . $tmp[2]]["id_exception"] = self::getIdException($tmp[2])["id"];
|
|
|
- } else {
|
|
|
- $data[$tmp[1] . "#" . $tmp[2]]["id_exception"] = NULL;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // Vide la table
|
|
|
- db::query("TRUNCATE TABLE " . DB_T_TYPE_ACCESS);
|
|
|
- db::execute();
|
|
|
-
|
|
|
- // Reconstruit la table
|
|
|
- foreach ($data as $keyData => $valueData) {
|
|
|
- db::query("INSERT INTO " . DB_T_TYPE_ACCESS . " (id, id_type, id_access, id_exception) VALUES (:id, :id_type, :id_access, :id_exception)");
|
|
|
- db::bind(':id', $keyData);
|
|
|
- db::bind(':id_type', $valueData["id_type"]);
|
|
|
- db::bind(':id_access', $valueData["id_access"]);
|
|
|
- db::bind(':id_exception', $valueData["id_exception"]);
|
|
|
- try {
|
|
|
- db::execute();
|
|
|
- } catch (Exception $ex) {
|
|
|
- alert::recError("Erreur à l'enregistrement des droits");
|
|
|
- if(debug::isFile("debug")) { alert::recError("Stack : " . $ex); }
|
|
|
- return FALSE;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return TRUE;
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
}
|