Brendan Abolivier 9 лет назад
Родитель
Сommit
a80b6acf62
8 измененных файлов: 65 добавлений и 32 удалений
  1. 1
    1
      controllers/data.php
  2. 4
    14
      controllers/document.php
  3. 1
    1
      controllers/promo.php
  4. 18
    14
      index.php
  5. 26
    0
      lib/platypuce.js
  6. 5
    0
      models/document.class.php
  7. 1
    0
      views/layout.html.php
  8. 9
    2
      views/list.html.php

+ 1
- 1
controllers/data.php Просмотреть файл

@@ -4,7 +4,7 @@ require_once(dirname(__DIR__)."/models/data.class.php");
4 4
 
5 5
 function data()
6 6
 {
7
-    set("title", "Titre");
7
+    set("title", "Données");
8 8
     set("data", Data::getAll());
9 9
     
10 10
     return html("list.html.php", "layout.html.php");

+ 4
- 14
controllers/document.php Просмотреть файл

@@ -5,7 +5,7 @@ require_once(dirname(__DIR__) . "/models/promo.class.php");
5 5
 
6 6
 function document()
7 7
 {
8
-    set("title", "Titre");
8
+    set("title", "Document");
9 9
     set("data", Document::getAll());
10 10
     set("promos", Promo::getAll());
11 11
 
@@ -14,24 +14,14 @@ function document()
14 14
 
15 15
 function add_document()
16 16
 {
17
-    File::addDocument($_FILES["document"], [
17
+    Document::addDocument($_FILES["document"], [
18 18
         "rang" => $_POST["rang"],
19 19
         "promo" => $_POST["promo"],
20 20
         "libelle" => $_POST["libelle"]
21 21
     ]);
22 22
 }
23 23
 
24
-function alter_document()
24
+function delete_document($fileid)
25 25
 {
26
-    $document = new Document($_POST["id"]);
27
-    
28
-    $document->setRang($_POST["rang"]);
29
-    $document->setPromo($_POST["promo"]);
30
-    $document->setLibelle($_POST["libelle"]);
31
-    $document->setFichier($_POST["fichier"]);
32
-}
33
-
34
-function delete_document()
35
-{
36
-    (new File($_POST["id"]))->erase();
26
+    (new Document($fileid))->erase();
37 27
 }

+ 1
- 1
controllers/promo.php Просмотреть файл

@@ -4,7 +4,7 @@ require_once(dirname(__DIR__)."/models/promo.class.php");
4 4
 
5 5
 function promo()
6 6
 {
7
-    set("title", "Titre");
7
+    set("title", "Promotions");
8 8
     set("data", Promo::getAll());
9 9
     
10 10
     return html("list.html.php", "layout.html.php");

+ 18
- 14
index.php Просмотреть файл

@@ -2,21 +2,25 @@
2 2
 
3 3
 require_once("lib/limonade.php");
4 4
 
5
-dispatch_get("/",                  "login");
6
-dispatch_get("/data",              "data");
7
-dispatch_get("/data/extract",      "data_extract");
8
-dispatch_get("/document",          "document");
9
-dispatch_get("/promo",             "promo");
5
+dispatch_get("/",                       "login");
6
+dispatch_get("/data",                   "data");
7
+dispatch_get("/data/extract",           "data_extract");
8
+dispatch_get("/document",               "document");
9
+dispatch_get("/promo",                  "promo");
10 10
 
11
-dispatch_post("/",                 "check_login");
12
-dispatch_post("/files",            "add_file");
13
-dispatch_post("/promo",            "add_promo");
11
+dispatch_post("/",                      "check_login");
12
+dispatch_post("/document",              "add_document");
13
+dispatch_post("/promo",                 "add_promo");
14 14
 
15
-dispatch_put("/data/:dataid",      "alter_data");
16
-dispatch_put("/files/:fileid",     "alter_file");
17
-dispatch_put("/promo/:promoid",    "alter_promo");
15
+dispatch_put("/data/:dataid",           "alter_data");
16
+dispatch_put("/promo/:promoid",         "alter_promo");
18 17
 
19
-dispatch_delete("/files/:fileid",  "delete_file");
20
-dispatch_delete("/promo/:promoid", "delete_promo");
18
+dispatch_delete("/document/:fileid",    "delete_document");
19
+dispatch_delete("/promo/:promoid",      "delete_promo");
21 20
 
22
-run();
21
+try {
22
+    run();
23
+}
24
+catch (Exception $e) {
25
+    error_log($e);
26
+}

+ 26
- 0
lib/platypuce.js Просмотреть файл

@@ -0,0 +1,26 @@
1
+var dataSelect = $("option")[0].value;
2
+
3
+$(document).on('change', 'select', function(e) {
4
+    dataSelect = this.options[e.target.selectedIndex].value;
5
+});
6
+
7
+$('#addForm').submit(function(e) {
8
+
9
+    e.preventDefault();
10
+    var data = new FormData();
11
+    data.append("document", $("#file")[0].files[0]);
12
+    data.append("promo", dataSelect);
13
+    data.append("rang", $("#rang").val());
14
+    data.append("libelle", $("#libelle").val());
15
+
16
+    $.ajax({
17
+        method: "POST",
18
+        url: "document",
19
+        data: data,
20
+        processData: false,
21
+        contentType: false,
22
+        complete: function (result) {
23
+            console.log(result);
24
+        }
25
+    });
26
+});

+ 5
- 0
models/document.class.php Просмотреть файл

@@ -64,13 +64,18 @@ class Document
64 64
 
65 65
         // Determining the folder to put the document in
66 66
         if (strstr($filename, "A1") || strstr($filename, "A2")) {
67
+            error_log("A1\n");
67 68
             $destination = "A12/" . $filename;
68 69
         } elseif (strstr($filename, "A3") || strstr($filename, "A4") || strstr($filename, "A5")) {
70
+            error_log("A3\n");
69 71
             $destination = "A345/" . $filename;
70 72
         } else {
73
+            error_log("meh\n");
71 74
             $destination = $filename;
72 75
         }
73 76
 
77
+        error_log($destination);
78
+
74 79
         move_uploaded_file($document["tmp_name"], __DIR__ . "../../pdf/" . $destination);
75 80
 
76 81
         foreach ($options as $key => $value) {

+ 1
- 0
views/layout.html.php Просмотреть файл

@@ -37,6 +37,7 @@
37 37
                 $("#mainTable").tablesorter();
38 38
             });
39 39
         </script>
40
+        <script src="lib/platypuce.js"></script>
40 41
     </body>
41 42
 
42 43
 </html>

+ 9
- 2
views/list.html.php Просмотреть файл

@@ -8,7 +8,7 @@
8 8
     <div class="well">
9 9
         <div class="form-group">
10 10
             <label for="promo">Promotion :</label>
11
-            <select>
11
+            <select id="promo">
12 12
                 <?php foreach($promos as $promo)
13 13
                 {
14 14
                     ?>
@@ -21,12 +21,19 @@
21 21
         </div>
22 22
         <div class="form-group">
23 23
             <label for="rang">Rang :</label>
24
-            <input type="number" class="form-control" />
24
+            <input type="number" class="form-control" id="rang" />
25 25
         </div>
26 26
         <div class="form-group">
27 27
             <label for="libelle">Libellé : </label>
28 28
             <input type="text" class="form-control" id="libelle" placeholder="Libellé" />
29 29
         </div>
30
+        <div class="form-group">
31
+            <label for="file">Fichier :</label>
32
+            <input type="file" id="file" />
33
+        </div>
34
+        <div class="form-group">
35
+            <input type="submit" class="form-control" value="Ajouter le document" id="formsubmit" />
36
+        </div>
30 37
     </div>
31 38
 </form>
32 39