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 getList(){ } 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 " . "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])){ return $tmp; } else { return NULL; } } 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){ echo '
    '; foreach ($_attachs as $key => $attach) { echo '
  1. '.$attach["name"].' ('.core::convertBytes($attach["size"]).')
    Chargé le '.core::convertDate($attach["creer"]).' par '.$attach["user"].'
    '; if($key == 0){ echo ' '; } else { echo '
    '; } echo '
  2. '; } 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 . ''; } } static public function badge(){ $tags = user::getIdTags(session::getId()); $nb = document::myAssign($tags); if($tags != NULL){ if($nb > 0){ echo ''; } } } }