Browse Source

Limited document

stany.ferer 1 year ago
parent
commit
d63f24627f

+ 41 - 23
core/class/access.class.php

@@ -31,13 +31,14 @@ class access
     public static function getAccessList(int $_idType = NULL)
     {
         ($_idType == NULL) ? $idType = session::getType() : $idType = $_idType;
-        $return["access"] = $return["noAccess"] = array();
+        $return["access"] = $return["noAccess"] = $return["exception"] = array();
 
         db::query("SELECT "
             . "" . DB_T_ACCESS . ".id, "
             . "" . DB_T_ACCESS . ".label, "
             . "" . DB_T_ACCESS . ".access, "
-            . "" . DB_T_ACCESS . ".noAccess "
+            . "" . DB_T_ACCESS . ".noAccess, "
+            . "" . 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 "
             . "WHERE " . DB_T_TYPE_ACCESS . ".id_type = :id_type ");
@@ -48,6 +49,7 @@ class access
             foreach ($tmp as $access) {
                 $return["access"] = self::addInArray($access["access"], $return["access"]);
                 $return["noAccess"] = self::addInArray($access["noAccess"], $return["noAccess"]);
+                if(isset($access["exception"])) { $return["exception"] = self::addInArray($access["exception"], $return["exception"]); }
             }
 
             // Je supprime les restriction d'accès en fonction des accès accordés
@@ -122,6 +124,7 @@ class access
         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 "
@@ -130,28 +133,34 @@ class access
 
         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(isset($return[$access["access"]][$type["type"]]) AND $return[$access["access"]][$type["type"]] == 1)
-                        { $return[$access["access"]][$type["type"]] = 1; 
-                        } elseif($type["id"] == $access["id_type"]) 
-                        { $return[$access["access"]][$type["type"]] = 1;
-                        } else 
-                        { $return[$access["access"]][$type["type"]] = 0;
-                        }
+                    $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;
+                        $return[$access["access"]]["Administrateur"] = 1;
                 }
 
                 foreach ($return as $value) {
@@ -163,15 +172,24 @@ class access
         }
     }
 
+    public static function ifLimitAccessException(string $_exception)
+    {
+        $accessList = self::getAccessList(session::getType());
+        return in_array($_exception, $accessList["exception"]) ? TRUE : FALSE;
+    }
+
     public static function ifAccesss(string $_accessAsk, int $_idType = NULL)
     {
         if (session::isConnect() == FALSE and self::checkAccessOffLine($_accessAsk)) {
             return TRUE;
         }
-        ($_idType == NULL) ? $idType = session::getType() : $idType = $_idType;
+
+        // Si Admin OK
+        $idType = $_idType == NULL ? session::getType() : $_idType;
         if ($idType == 1) {
             return TRUE;
-        } // Si Admin OK
+        } 
+        // Si Admin OK
 
         $accessList = self::getAccessList($idType);
 

+ 10 - 2
core/class/get.class.php

@@ -70,11 +70,19 @@ class get
     {
         if (core::ifGet("file")) {
             if (access::check(core::getGet("file"), "json")) {
-                if (file_exists(DIR_DATAS_JSON . core::getGet("file") . '.json')) {
+                // Exception 
+                    if(core::getGet("file") == "documents" AND access::ifLimitAccessException("salaire")){ 
+                        $file = "documents-limited";
+                    } else {
+                        $file = core::getGet("file");
+                    }
+                // Exception
+                if (file_exists(DIR_DATAS_JSON . $file . '.json')) {
                     header('Content-type: application/json');
-                    require_once DIR_DATAS_JSON . core::getGet("file") . '.json';
+                    require_once DIR_DATAS_JSON . $file . '.json';
                     exit();
                 } else {
+                    echo json_encode("['No found']");
                     exit();
                 }
             } else {

+ 16 - 3
core/class/json.class.php

@@ -50,6 +50,9 @@ class json extends db
                 case "documents":
                     return self::create_document();
                     break;
+                case "documents-limited":
+                    return self::create_document("limited");
+                    break;
             }
         } else {
             return 0;
@@ -190,8 +193,18 @@ class json extends db
         return (sftp::testAccessHost()) ? "OK" : "KO";
     }
 
-    private static function create_document()
+    private static function create_document(string $_limited = NULL)
     {
+        $where = ($_limited == TRUE) ? " WHERE " . DB_T_DOCUMENTS . ".id_type != 3" : NULL;
+
+        if(is_null($_limited)){
+            $where = NULL;
+            $file = "documents";
+        } else {
+            $where = " WHERE " . DB_T_DOCUMENTS . ".id_type != 3";
+            $file = "documents-limited";
+        }
+        
         db::query("SELECT 
         " . DB_T_DOCUMENTS . ".id, 
         " . DB_T_DOCUMENTS . ".titre, 
@@ -212,11 +225,11 @@ class json extends db
         IF(" . DB_T_DOCUMENTS . ".id_user_done IS NOT NULL, 'Traité', 'Non traité') AS done, 
         " . DB_T_TYPE_DOCUMENT . ".label
         FROM " . DB_T_DOCUMENTS . " 
-        INNER JOIN " . DB_T_TYPE_DOCUMENT . " ON " . DB_T_TYPE_DOCUMENT . ".id = " . DB_T_DOCUMENTS . ".id_type");
+        INNER JOIN " . DB_T_TYPE_DOCUMENT . " ON " . DB_T_TYPE_DOCUMENT . ".id = " . DB_T_DOCUMENTS . ".id_type" . $where);
 
         $row =  db::resultset();
 
-        if (file_put_contents(DIR_DATAS_JSON . "documents.json", json_encode($row))) {
+        if (file_put_contents(DIR_DATAS_JSON . $file . ".json", json_encode($row))) {
             return 1;
         } else {
             return 0;

+ 1 - 0
core/class/maj.class.php

@@ -146,6 +146,7 @@ class maj {
             json::create("banque-lignes-4");
             json::create("banque-csv");
             json::create("documents");
+            json::create("documents-limited");
         }
 
         self::printSeparateur();

+ 1 - 0
core/submit/cms.document-delete.php

@@ -3,6 +3,7 @@
 if(core::ifGet("id")) {
     document::delete(core::getGet("id"));
     json::create("documents");
+    json::create("documents-limited");
 
     historique::recRef("/document-" . core::getGet("id").".html");
     historique::add(array(

+ 1 - 0
core/submit/cms.document.php

@@ -16,6 +16,7 @@ if (core::ifPost("from") AND core::getPost("from") == "document") {
     }
 
     json::create("documents");
+    json::create("documents-limited");
     document::cleanOrphanTags();
 
     header("Location: " . $location);

+ 1 - 0
core/submit/cms.parametres-json-refresh.php

@@ -13,6 +13,7 @@ json::create("banque-lignes-3");
 json::create("banque-lignes-4");
 json::create("banque-csv");
 json::create("documents");
+json::create("documents-limited");
 
 historique::recRef("/parametres.html");
 historique::add(array(

+ 1 - 0
core/submit/cms.tag-change.php

@@ -4,6 +4,7 @@ if (core::ifPost("from")) {
 
     tags::maj(core::getPost("id"), core::getPost("value"));
     json::create("documents");
+    json::create("documents-limited");
 
     historique::recRef("/tags.html");
     historique::add(array(

+ 4 - 2
core/views/pages/cms.document.php

@@ -14,7 +14,7 @@ if (core::getGet("id") == NULL) {
     $document = $datas["document"];
     $files = $datas["files"];
 
-    if (empty($document["id"])) {
+    if (empty($document["id"]) OR access::ifLimitAccessException("salaire") AND isset($document["id_type"]) AND $document["id_type"] == 3) {
         get::page("unknow");
         exit();
     }
@@ -93,7 +93,9 @@ if (isset($document["id"])) {
                     <option value=""></option>
                     <option value="1" <?php core::printFormSelectOption($_type_document, 1) ?>><?php echo $_label_type_document[1] ?></option>
                     <option value="2" <?php core::printFormSelectOption($_type_document, 2) ?>><?php echo $_label_type_document[2] ?></option>
-                    <option value="3" <?php core::printFormSelectOption($_type_document, 3) ?>><?php echo $_label_type_document[3] ?></option>
+                    <?php if (!access::ifLimitAccessException("salaire")) { ?>
+                        <option value="3" <?php core::printFormSelectOption($_type_document, 3) ?>><?php echo $_label_type_document[3] ?></option>
+                    <?php } ?>
                     <option value="0" <?php core::printFormSelectOption($_type_document, 0) ?>><?php echo $_label_type_document[0] ?></option>
                 </select>
             </div>

+ 1 - 0
core/views/pages/cms.parametre-teams.php

@@ -42,6 +42,7 @@ echo core::filAriane(array(
 <script>
     function checkFormatter(value) { 
         if(value === 1){ var color = "#d4edda;"; var txt = "Autorisé"; }
+        else if(value === 2){ var color = "#ffeeba;"; var txt = "Partiellement"; }
         else { var color = "#f8d7da"; var txt = "-"; }
         return '<div with:100% height:20px style="background-color:'+color+'; text-align:center;">' + txt + '</div>'
     }

+ 6 - 1
maj/sql/maj.sql

@@ -1,2 +1,7 @@
 
-UPDATE `access` SET `access` = 'document*\ndocuments\nadd-document' WHERE `access`.`id` = 16; 
+UPDATE `type_access` SET `id` = '4#16' WHERE `type_access`.`id_type` = 4 AND `type_access`.`id_access` = 16; 
+DELETE FROM type_access WHERE `type_access`.`id` = '6#1'
+INSERT INTO `type_access` (`id`, `id_type`, `id_access`) VALUES ('6#16', '6', '16');
+ALTER TABLE `type_access` ADD `exception` VARCHAR(1000) NULL AFTER `id_access`; 
+UPDATE `type_access` SET `exception` = 'salaire' WHERE `type_access`.`id` = '4#16'; 
+UPDATE `type_access` SET `exception` = 'salaire' WHERE `type_access`.`id` = '6#16';