file($filePatch); header('Content-Type: ' . $mime_type); header('Content-Length: ' . filesize($filePatch)); readfile($filePatch); } else { echo "Le fichier n'a pas été trouvé ou n'est pas lisible."; } } static public function get(float $_id){ db::query("SELECT " . "" . DB_T_DOCUMENTS . ".id, " . "" . DB_T_DOCUMENTS . ".id_type, " . "" . DB_T_DOCUMENTS . ".titre, " . "" . DB_T_DOCUMENTS . ".date, " . "" . DB_T_DOCUMENTS . ".deadline, " . "" . DB_T_DOCUMENTS . ".description, " . "" . DB_T_DOCUMENTS . ".montant, " . "" . DB_T_DOCUMENTS . ".id_user_done, " . "" . DB_T_DOCUMENTS . ".date_done, " . "CONCAT(" . DB_T_USER . ".prenom, ' ', " . DB_T_USER . ".nom) AS doneUser " . "FROM " . DB_T_DOCUMENTS . " " . "LEFT JOIN " . DB_T_USER . " ON " . DB_T_USER . ".id = " . DB_T_DOCUMENTS . ".id_user_done " . "WHERE " . DB_T_DOCUMENTS . ".id = :id"); db::bind(':id', $_id); $document = db::single(); $document["tagsSupplier"] = self::getTags($_id, 2); $document["tagsUser"] = self::getTags($_id, 1); $files = self::getFiles($_id); return array("document" => $document, "files" => $files); } static public function getTags(float $_idDocument, float $_idTypeTags){ db::query("SELECT " . "" . DB_T_TAGS . ".label " . "FROM " . DB_T_DOCUMENT_TAGS . " " . "INNER JOIN " . DB_T_TAGS . " ON " . DB_T_TAGS . ".id = " . DB_T_DOCUMENT_TAGS . ".id_tags " . "WHERE " . DB_T_DOCUMENT_TAGS . ".id_documents = :idDocument AND " . DB_T_DOCUMENT_TAGS . ".id_type_tags = :idTypeTags " . "ORDER BY " . DB_T_DOCUMENT_TAGS . ".creer ASC"); db::bind(':idDocument', $_idDocument); db::bind(':idTypeTags', $_idTypeTags); $tmp = db::resultset(); if(isset($tmp[0])){ $return = NULL; foreach ($tmp as $value) { $return .= $value["label"].","; } $return = substr($return, 0, -1); return $return; } else { return NULL; } } static public function getFiles(float $_idDocument){ db::query("SELECT " . "" . DB_T_FILES . ".id, " . "" . DB_T_FILES . ".name, " . "" . DB_T_FILES . ".size, " . "" . DB_T_FILES . ".creer, " . "" . DB_T_FILES . ".id_user, " . "CONCAT(" . DB_T_USER . ".prenom, ' ', " . DB_T_USER . ".nom) AS user, " . "" . DB_T_DOCUMENT_FILES . ".principal " . "FROM " . DB_T_DOCUMENT_FILES . " " . "INNER JOIN " . DB_T_FILES . " ON " . DB_T_FILES . ".id = " . DB_T_DOCUMENT_FILES . ".id_files " . "INNER JOIN " . DB_T_USER . " ON " . DB_T_USER . ".id = " . DB_T_FILES . ".id_user " . "WHERE " . DB_T_DOCUMENT_FILES . ".id_documents = :id " . "ORDER BY " . DB_T_FILES . ".creer"); db::bind(':id', $_idDocument); $tmp = db::resultset(); if(isset($tmp[0])){ foreach ($tmp as $file) { if($file["principal"] == TRUE){ $return["principal"] = $file; } else { $return[] = $file; } } if(empty($return["principal"])){ $return["principal"] = $return[0]; self::principalFile($_idDocument, $return["principal"]["id"]); unset($return[0]); } return $return; } else { return NULL; } } static public function principalFile(float $_idDocument, string $_idFile){ db::query("UPDATE " . DB_T_DOCUMENT_FILES . " SET principal = :principal WHERE id_documents = :id_documents"); db::bind(':principal', 0); db::bind(':id_documents', $_idDocument); db::execute(); db::query("UPDATE " . DB_T_DOCUMENT_FILES . " SET principal = :principal WHERE id_documents = :id_documents AND id_files = :id_files"); db::bind(':principal', 1); db::bind(':id_documents', $_idDocument); db::bind(':id_files', $_idFile); db::execute(); } static public function getAssignMe(){ $tags = user::getIdTags(session::getId()); $where = NULL; foreach ($tags AS $key => $value) { if($key == 0){ $where = "WHERE " . DB_T_DOCUMENTS . ".id_user_done IS NULL AND " . DB_T_DOCUMENT_TAGS . ".id_tags = " . $value . ""; } else { $where .= " OR " . DB_T_DOCUMENT_TAGS . ".id_tags = " . $value . ""; } } db::query("SELECT " . DB_T_DOCUMENTS . ".id, " . DB_T_DOCUMENTS . ".titre, " . DB_T_DOCUMENTS . ".date, " . DB_T_DOCUMENTS . ".deadline, " . DB_T_DOCUMENTS . ".description, " . DB_T_DOCUMENTS . ".montant, ( SELECT GROUP_CONCAT(" . DB_T_TAGS . ".label SEPARATOR ', ') FROM " . DB_T_DOCUMENT_TAGS . " INNER JOIN " . DB_T_TAGS . " ON " . DB_T_TAGS . ".id = " . DB_T_DOCUMENT_TAGS . ".id_tags WHERE id_documents = " . DB_T_DOCUMENTS . ".id AND " . DB_T_DOCUMENT_TAGS . ".id_type_tags = 2 ORDER BY " . DB_T_DOCUMENT_TAGS . ".creer) AS tags, ( SELECT GROUP_CONCAT(" . DB_T_TAGS . ".label SEPARATOR ', ') FROM " . DB_T_DOCUMENT_TAGS . " INNER JOIN " . DB_T_TAGS . " ON " . DB_T_TAGS . ".id = " . DB_T_DOCUMENT_TAGS . ".id_tags WHERE id_documents = " . DB_T_DOCUMENTS . ".id AND " . DB_T_DOCUMENT_TAGS . ".id_type_tags = 1 ORDER BY " . DB_T_DOCUMENT_TAGS . ".creer) AS assign, " . DB_T_TYPE_DOCUMENT . ".label FROM " . DB_T_DOCUMENT_TAGS . " INNER JOIN " . DB_T_DOCUMENTS . " ON " . DB_T_DOCUMENTS . ".id = " . DB_T_DOCUMENT_TAGS . ".id_documents INNER JOIN " . DB_T_TYPE_DOCUMENT . " ON " . DB_T_TYPE_DOCUMENT . ".id = " . DB_T_DOCUMENTS . ".id_type " . $where); return db::resultset(); } static public function printAttachement(array $_attachs){ $principal = $_attachs["principal"]; echo '
    '; echo '
  1. '.$principal["name"].' ('.core::convertBytes($principal["size"]).')
    Chargé le '.core::convertDate($principal["creer"]).' par '.$principal["user"].'
  2. '; foreach ($_attachs as $key => $attach) { if($key != "principal"){ echo '
  3. '.$attach["name"].' ('.core::convertBytes($attach["size"]).')
    Chargé le '.core::convertDate($attach["creer"]).' par '.$attach["user"].'
  4. '; } } echo '

'; } static public function myAssign(?array $_tags = NULL){ if($_tags == NULL){ return NULL; } else { $where = NULL; foreach ($_tags AS $key => $value) { if($key == 0){ $where = "WHERE " . DB_T_DOCUMENTS . ".id_user_done IS NULL AND " . DB_T_DOCUMENT_TAGS . ".id_tags = " . $value . ""; } else { $where .= " OR " . DB_T_DOCUMENT_TAGS . ".id_tags = " . $value . ""; } } } db::query("SELECT " . "COUNT(" . DB_T_DOCUMENT_TAGS . ".id_tags) AS nb " . "FROM " . DB_T_DOCUMENT_TAGS . " " . "INNER JOIN " . DB_T_DOCUMENTS . " ON " . DB_T_DOCUMENTS . ".id = " . DB_T_DOCUMENT_TAGS . ".id_documents " . $where); return db::single()["nb"]; } static public function menu(){ $tags = user::getIdTags(session::getId()); $nb = document::myAssign($tags); if($tags != NULL){ $badge = ""; if($nb > 0){ $badge = '' . $nb . ''; } echo 'Vos assignations' . $badge . ''; } if(maj::compareHash() == FALSE AND access::ifAccesss("parametres")){ echo 'Nouvelle version'; } } static public function badge(){ $pastille = 0; $tags = user::getIdTags(session::getId()); $nb = document::myAssign($tags); if(maj::compareHash() == FALSE AND access::ifAccesss("parametres")){ $pastille = 1; } if($tags != NULL AND $nb > 0){ $pastille = 1; } if($pastille == 1){ if($nb > 0){ echo ''; } } } }