|
@@ -16,7 +16,15 @@ class document
|
|
|
return file::download($_id, DIR_DATAS_DOCS);
|
|
return file::download($_id, DIR_DATAS_DOCS);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- static public function deleteFile(float $_id){
|
|
|
|
|
|
|
+ static public function deleteFile(string $_id){
|
|
|
|
|
+ db::query("DELETE FROM ". DB_T_DOCUMENT_FILES ." WHERE id_files = :id_files");
|
|
|
|
|
+ db::bind(':id_files', $_id);
|
|
|
|
|
+ db::execute();
|
|
|
|
|
+
|
|
|
|
|
+ file::delete($_id, DIR_DATAS_DOCS);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ static public function deleteFiles(float $_id){
|
|
|
foreach (self::getFiles($_id) as $file) {
|
|
foreach (self::getFiles($_id) as $file) {
|
|
|
|
|
|
|
|
db::query("DELETE FROM ". DB_T_DOCUMENT_FILES ." WHERE id_files = :id_files");
|
|
db::query("DELETE FROM ". DB_T_DOCUMENT_FILES ." WHERE id_files = :id_files");
|
|
@@ -41,7 +49,7 @@ class document
|
|
|
db::bind(':id_documents', $_id);
|
|
db::bind(':id_documents', $_id);
|
|
|
db::execute();
|
|
db::execute();
|
|
|
|
|
|
|
|
- self::deleteFile($_id);
|
|
|
|
|
|
|
+ self::deleteFiles($_id);
|
|
|
|
|
|
|
|
db::query("DELETE FROM " . DB_T_DOCUMENTS . " WHERE id = :id");
|
|
db::query("DELETE FROM " . DB_T_DOCUMENTS . " WHERE id = :id");
|
|
|
db::bind(':id', $_id);
|
|
db::bind(':id', $_id);
|
|
@@ -159,51 +167,82 @@ class document
|
|
|
|
|
|
|
|
public static function update()
|
|
public static function update()
|
|
|
{
|
|
{
|
|
|
- try {
|
|
|
|
|
- $tagsUser = tags::textToId(core::getPost("tagsUser"), 1);
|
|
|
|
|
- self::addTags(core::getPost("id"), $tagsUser, 1);
|
|
|
|
|
-
|
|
|
|
|
- $tagsSupplier = tags::textToId(core::getPost("tagsSupplier"), 2); echo $tagsSupplier;
|
|
|
|
|
- self::addTags(core::getPost("id"), $tagsSupplier, 2);
|
|
|
|
|
- } catch (Exception $ex) {
|
|
|
|
|
- alert::recError("Erreur à l'enregistrement de la liaison : " . core::getPost("id"));
|
|
|
|
|
- return FALSE;
|
|
|
|
|
|
|
+ if(core::ifFiles("attachement-document") == TRUE){
|
|
|
|
|
+ $file = core::getFiles("attachement-document");
|
|
|
|
|
+ $md5 = md5_file($file["tmp_name"]);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- if(core::ifPost("done") AND core::getPost("done") == TRUE){
|
|
|
|
|
- $sql = ", id_user_done = :id_user_done, date_done = CURRENT_TIMESTAMP ";
|
|
|
|
|
|
|
+ if(isset($md5) AND file::findM5($md5) == TRUE){
|
|
|
|
|
+ alert::recError("Le fichier \"" . $file["name"] . "\" a déjà été utilisé");
|
|
|
|
|
+ session::setTemp(core::getPost(), "document");
|
|
|
} else {
|
|
} else {
|
|
|
- $sql = "";
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- db::query("UPDATE " . DB_T_DOCUMENTS . " SET "
|
|
|
|
|
- . "id_type = :id_type, "
|
|
|
|
|
- . "titre = :titre, "
|
|
|
|
|
- . "date = :date, "
|
|
|
|
|
- . "deadline = :deadline, "
|
|
|
|
|
- . "description = :description "
|
|
|
|
|
- . $sql
|
|
|
|
|
- . "WHERE id = :id");
|
|
|
|
|
-
|
|
|
|
|
- db::bind(':id_type', core::getPost("id_type"));
|
|
|
|
|
- db::bind(':titre', core::getPost("titre"));
|
|
|
|
|
- db::bind(':date', core::getPost("date"));
|
|
|
|
|
- db::bind(':deadline', core::getPost("deadline"));
|
|
|
|
|
- db::bind(':description', core::getPost("description"));
|
|
|
|
|
- db::bind(':id', core::getPost("id"));
|
|
|
|
|
-
|
|
|
|
|
- if(core::ifPost("done") AND core::getPost("done") == TRUE){
|
|
|
|
|
- db::bind(':id_user_done', session::getId());
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- try {
|
|
|
|
|
- db::execute();
|
|
|
|
|
- alert::recSuccess("Document mis à jour avec succès");
|
|
|
|
|
- return TRUE;
|
|
|
|
|
|
|
+ if(isset($md5)){
|
|
|
|
|
+ try {
|
|
|
|
|
+ $idFile = self::uploadFile($file);
|
|
|
|
|
+ } catch (Exception $ex) {
|
|
|
|
|
+ alert::recError("Erreur à l'enregistrement de la pièce jointe : " . $idFile);
|
|
|
|
|
+ return FALSE;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ self::addFile(core::getPost("id"), $idFile);
|
|
|
|
|
+ } catch (Exception $ex) {
|
|
|
|
|
+ alert::recError("Erreur à l'enregistrement de la liaison : " . $idFile);
|
|
|
|
|
+ return FALSE;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if(core::getPost("delete-attachement")){
|
|
|
|
|
+ foreach (core::getPost("delete-attachement") as $deleteAttach) {
|
|
|
|
|
+ self::deleteFile($deleteAttach);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ $tagsUser = tags::textToId(core::getPost("tagsUser"), 1);
|
|
|
|
|
+ self::addTags(core::getPost("id"), $tagsUser, 1);
|
|
|
|
|
+
|
|
|
|
|
+ $tagsSupplier = tags::textToId(core::getPost("tagsSupplier"), 2); echo $tagsSupplier;
|
|
|
|
|
+ self::addTags(core::getPost("id"), $tagsSupplier, 2);
|
|
|
} catch (Exception $ex) {
|
|
} catch (Exception $ex) {
|
|
|
- alert::recError("Erreur de mise à jour du document : " . $ex);
|
|
|
|
|
|
|
+ alert::recError("Erreur à l'enregistrement de la liaison : " . core::getPost("id"));
|
|
|
return FALSE;
|
|
return FALSE;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ if(core::ifPost("done") AND core::getPost("done") == TRUE){
|
|
|
|
|
+ $sql = ", id_user_done = :id_user_done, date_done = CURRENT_TIMESTAMP ";
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $sql = "";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ db::query("UPDATE " . DB_T_DOCUMENTS . " SET "
|
|
|
|
|
+ . "id_type = :id_type, "
|
|
|
|
|
+ . "titre = :titre, "
|
|
|
|
|
+ . "date = :date, "
|
|
|
|
|
+ . "deadline = :deadline, "
|
|
|
|
|
+ . "description = :description "
|
|
|
|
|
+ . $sql
|
|
|
|
|
+ . "WHERE id = :id");
|
|
|
|
|
+
|
|
|
|
|
+ db::bind(':id_type', core::getPost("id_type"));
|
|
|
|
|
+ db::bind(':titre', core::getPost("titre"));
|
|
|
|
|
+ db::bind(':date', core::getPost("date"));
|
|
|
|
|
+ db::bind(':deadline', core::getPost("deadline"));
|
|
|
|
|
+ db::bind(':description', core::getPost("description"));
|
|
|
|
|
+ db::bind(':id', core::getPost("id"));
|
|
|
|
|
+
|
|
|
|
|
+ if(core::ifPost("done") AND core::getPost("done") == TRUE){
|
|
|
|
|
+ db::bind(':id_user_done', session::getId());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ db::execute();
|
|
|
|
|
+ alert::recSuccess("Document mis à jour avec succès");
|
|
|
|
|
+ return TRUE;
|
|
|
|
|
+ } catch (Exception $ex) {
|
|
|
|
|
+ alert::recError("Erreur de mise à jour du document : " . $ex);
|
|
|
|
|
+ return FALSE;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
static public function printFile(string $_id) {
|
|
static public function printFile(string $_id) {
|
|
@@ -298,4 +337,29 @@ class document
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ static public function printAttachement(array $_attachs){
|
|
|
|
|
+ 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"].'">
|
|
|
|
|
+ <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\')"><i class="bi bi-eye-fill"></i></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\')"><i class="bi bi-eye-fill"></i></button>
|
|
|
|
|
+ <button type="button" class="btn btn-outline-danger" onclick="deleteAttachment(\''.$attach["id"].'\')" id="button-attach-'.$attach["id"].'"><i class="bi bi-trash"></i></button>
|
|
|
|
|
+ </div>';
|
|
|
|
|
+ }
|
|
|
|
|
+ echo '</li>';
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ echo '</ol><br />';
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|