|
|
@@ -74,15 +74,19 @@ class document
|
|
|
return db::single()["id"];
|
|
|
}
|
|
|
|
|
|
- private static function addFile(float $_idDocument, string $_idFile)
|
|
|
+ private static function addFile(float $_idDocument, string $_idFile, int $_principal = NULL)
|
|
|
{
|
|
|
- db::query("INSERT INTO " . DB_T_DOCUMENT_FILES . " (id_documents, id_files) VALUES (:id_documents, :id_files)");
|
|
|
+ db::query("INSERT INTO " . DB_T_DOCUMENT_FILES . " (id_documents, id_files, principal) VALUES (:id_documents, :id_files, :principal)");
|
|
|
db::bind(':id_documents', $_idDocument);
|
|
|
db::bind(':id_files', $_idFile);
|
|
|
+ db::bind(':principal', $_principal);
|
|
|
try {
|
|
|
db::execute();
|
|
|
return TRUE;
|
|
|
} catch (Exception $ex) {
|
|
|
+ echo "error";
|
|
|
+ echo $ex;
|
|
|
+ exit();
|
|
|
return FALSE;
|
|
|
}
|
|
|
}
|
|
|
@@ -168,7 +172,7 @@ class document
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
- self::addFile($lastId, $idFile);
|
|
|
+ self::addFile($lastId, $idFile, 1);
|
|
|
} catch (Exception $ex) {
|
|
|
alert::recError("Erreur à l'enregistrement de la liaison : " . $idFile);
|
|
|
if(core::isDebug()) { alert::recError("Stack : " . $ex); }
|
|
|
@@ -211,7 +215,7 @@ class document
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
- self::addFile(core::getPost("id"), $idFile);
|
|
|
+ self::addFile(core::getPost("id"), $idFile, 0);
|
|
|
} catch (Exception $ex) {
|
|
|
alert::recError("Erreur à l'enregistrement de la liaison : " . $idFile);
|
|
|
return FALSE;
|
|
|
@@ -224,6 +228,10 @@ class document
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ if(core::getPost("default-attachement")){
|
|
|
+ self::principalFile(core::getPost("id"), core::getPost("default-attachement"));
|
|
|
+ }
|
|
|
+
|
|
|
try {
|
|
|
$tagsUser = tags::textToId(core::getPost("tagsUser"), 1);
|
|
|
self::addTags(core::getPost("id"), $tagsUser, 1);
|
|
|
@@ -290,10 +298,6 @@ class document
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- static public function getList(){
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
static public function get(float $_id){
|
|
|
db::query("SELECT "
|
|
|
. "" . DB_T_DOCUMENTS . ".id, "
|
|
|
@@ -352,7 +356,8 @@ class document
|
|
|
. "" . DB_T_FILES . ".size, "
|
|
|
. "" . DB_T_FILES . ".creer, "
|
|
|
. "" . DB_T_FILES . ".id_user, "
|
|
|
- . "CONCAT(" . DB_T_USER . ".prenom, ' ', " . DB_T_USER . ".nom) AS 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 "
|
|
|
@@ -362,12 +367,38 @@ class document
|
|
|
$tmp = db::resultset();
|
|
|
|
|
|
if(isset($tmp[0])){
|
|
|
- return $tmp;
|
|
|
+ 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());
|
|
|
@@ -388,12 +419,12 @@ class document
|
|
|
" . DB_T_DOCUMENTS . ".deadline,
|
|
|
" . DB_T_DOCUMENTS . ".description,
|
|
|
" . DB_T_DOCUMENTS . ".montant,
|
|
|
- ( SELECT GROUP_CONCAT(" . DB_T_TAGS . ".label SEPARATOR ', ')
|
|
|
+ ( 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 ', ')
|
|
|
+ ( 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
|
|
|
@@ -408,26 +439,29 @@ class document
|
|
|
}
|
|
|
|
|
|
static public function printAttachement(array $_attachs){
|
|
|
+ $principal = $_attachs["principal"];
|
|
|
echo '<ol class="list-group list-group-numbered">';
|
|
|
- foreach ($_attachs as $key => $attach) {
|
|
|
- echo '<li class="list-group-item d-flex justify-content-between align-items-start" id="attach-'.$attach["id"].'">
|
|
|
+ echo ' <li class="list-group-item d-flex justify-content-between align-items-start" id="attach-'.$principal["id"].'">
|
|
|
<div class="ms-2 me-auto">
|
|
|
- <div><span class="fw-bold">'.$attach["name"].'</span> ('.core::convertBytes($attach["size"]).')</div>
|
|
|
- Chargé le '.core::convertDate($attach["creer"]).' par '.$attach["user"].'
|
|
|
- <div id="select-attach-'.$attach["id"].'" style="color:red;"></div>
|
|
|
- </div>';
|
|
|
- if($key == 0){
|
|
|
- echo '
|
|
|
- <button type="button" class="btn btn btn-outline-primary" onclick="window.open(\'/document.php?id=' . $attach["id"] . '\', \'_blank\')">' . icon::getFont(["icon" => "bi bi-eye-fill"]) . '</button>
|
|
|
- ';
|
|
|
- } else {
|
|
|
- echo '<div class="btn-group">
|
|
|
- <button type="button" class="btn btn btn-outline-primary" onclick="window.open(\'/document.php?id=' . $attach["id"] . '\', \'_blank\')">' . icon::getFont(["icon" => "bi bi-eye-fill"]) . '</button>
|
|
|
- <button type="button" class="btn btn-outline-danger" onclick="deleteAttachment(\''.$attach["id"].'\')" id="button-attach-'.$attach["id"].'">' . icon::getFont(["icon" => "bi bi-trash"]) . '</button>
|
|
|
- </div>';
|
|
|
- }
|
|
|
- echo '</li>';
|
|
|
-
|
|
|
+ <div><span class="fw-bold">'.$principal["name"].'</span> ('.core::convertBytes($principal["size"]).')</div>
|
|
|
+ Chargé le '.core::convertDate($principal["creer"]).' par '.$principal["user"].'
|
|
|
+ <div id="select-attach-'.$principal["id"].'" style="color:red;"></div>
|
|
|
+ </div><button type="button" class="btn btn btn-outline-secondary" onclick="window.open(\'/document.php?id=' . $principal["id"] . '\', \'_blank\')">' . icon::getFont(["icon" => "bi bi-eye-fill"]) . '</button>
|
|
|
+ </li>';
|
|
|
+ foreach ($_attachs as $key => $attach) {
|
|
|
+ if($key != "principal"){
|
|
|
+ echo ' <li class="list-group-item d-flex justify-content-between align-items-start" id="attach-'.$attach["id"].'">
|
|
|
+ <div class="ms-2 me-auto">
|
|
|
+ <div><span class="fw-bold">'.$attach["name"].'</span> ('.core::convertBytes($attach["size"]).')</div>
|
|
|
+ Chargé le '.core::convertDate($attach["creer"]).' par '.$attach["user"].'
|
|
|
+ <div id="select-attach-'.$attach["id"].'"></div>
|
|
|
+ </div><div class="btn-group">
|
|
|
+ <button type="button" class="btn btn btn-outline-secondary" onclick="window.open(\'/document.php?id=' . $attach["id"] . '\', \'_blank\')">' . icon::getFont(["icon" => "bi bi-eye-fill"]) . '</button>
|
|
|
+ <button type="button" class="btn btn btn-outline-primary" onclick="defaultAttachment(\''.$attach["id"].'\')" id="button-default-'.$attach["id"].'">' . icon::getFont(["icon" => "bi bi-paperclip"]) . '</button>
|
|
|
+ <button type="button" class="btn btn-outline-danger" onclick="deleteAttachment(\''.$attach["id"].'\')" id="button-delete-'.$attach["id"].'">' . icon::getFont(["icon" => "bi bi-trash"]) . '</button>
|
|
|
+ </div>
|
|
|
+ </li>';
|
|
|
+ }
|
|
|
}
|
|
|
echo '</ol><br />';
|
|
|
}
|