Browse Source

Bunch of stuff

Brendan Abolivier 9 years ago
parent
commit
a80b6acf62
8 changed files with 65 additions and 32 deletions
  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 View File

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

+ 4
- 14
controllers/document.php View File

5
 
5
 
6
 function document()
6
 function document()
7
 {
7
 {
8
-    set("title", "Titre");
8
+    set("title", "Document");
9
     set("data", Document::getAll());
9
     set("data", Document::getAll());
10
     set("promos", Promo::getAll());
10
     set("promos", Promo::getAll());
11
 
11
 
14
 
14
 
15
 function add_document()
15
 function add_document()
16
 {
16
 {
17
-    File::addDocument($_FILES["document"], [
17
+    Document::addDocument($_FILES["document"], [
18
         "rang" => $_POST["rang"],
18
         "rang" => $_POST["rang"],
19
         "promo" => $_POST["promo"],
19
         "promo" => $_POST["promo"],
20
         "libelle" => $_POST["libelle"]
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 View File

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

+ 18
- 14
index.php View File

2
 
2
 
3
 require_once("lib/limonade.php");
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 View File

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 View File

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

+ 1
- 0
views/layout.html.php View File

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

+ 9
- 2
views/list.html.php View File

8
     <div class="well">
8
     <div class="well">
9
         <div class="form-group">
9
         <div class="form-group">
10
             <label for="promo">Promotion :</label>
10
             <label for="promo">Promotion :</label>
11
-            <select>
11
+            <select id="promo">
12
                 <?php foreach($promos as $promo)
12
                 <?php foreach($promos as $promo)
13
                 {
13
                 {
14
                     ?>
14
                     ?>
21
         </div>
21
         </div>
22
         <div class="form-group">
22
         <div class="form-group">
23
             <label for="rang">Rang :</label>
23
             <label for="rang">Rang :</label>
24
-            <input type="number" class="form-control" />
24
+            <input type="number" class="form-control" id="rang" />
25
         </div>
25
         </div>
26
         <div class="form-group">
26
         <div class="form-group">
27
             <label for="libelle">Libellé : </label>
27
             <label for="libelle">Libellé : </label>
28
             <input type="text" class="form-control" id="libelle" placeholder="Libellé" />
28
             <input type="text" class="form-control" id="libelle" placeholder="Libellé" />
29
         </div>
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
     </div>
37
     </div>
31
 </form>
38
 </form>
32
 
39