Przeglądaj źródła

Currently in a rush, so committing a lot of stuff without consistency. Please note that the JS event handlers don't work right now

Brendan Abolivier 9 lat temu
rodzic
commit
b4efee0d9d

+ 6
- 2
controllers/document.php Wyświetl plik

@@ -5,7 +5,7 @@ require_once(dirname(__DIR__) . "/models/promo.class.php");
5 5
 
6 6
 function document()
7 7
 {
8
-    set("title", "Document");
8
+    set("title", "Documents");
9 9
     set("data", Document::getAll());
10 10
     set("promos", Promo::getAll());
11 11
 
@@ -14,11 +14,15 @@ function document()
14 14
 
15 15
 function add_document()
16 16
 {
17
-    Document::addDocument($_FILES["document"], [
17
+    $filePath = Document::addDocument($_FILES["document"], [
18 18
         "rang" => $_POST["rang"],
19 19
         "promo" => $_POST["promo"],
20 20
         "libelle" => $_POST["libelle"]
21 21
     ]);
22
+
23
+    json_encode(array(
24
+        "path" => $filePath
25
+    ));
22 26
 }
23 27
 
24 28
 function delete_document($fileid)

+ 5
- 0
controllers/login.php Wyświetl plik

@@ -4,6 +4,11 @@ require_once(dirname(__DIR__)."/controllers/data.php");
4 4
 require_once(dirname(__DIR__)."/models/data.class.php");
5 5
 require_once(dirname(__DIR__)."/../DbIds.php");
6 6
 
7
+function getAdminIdentifiers()
8
+{
9
+    return ["toto", "tata"];
10
+}
11
+
7 12
 function login()
8 13
 {
9 14
     set("title", "Login");

+ 4
- 4
controllers/promo.php Wyświetl plik

@@ -18,15 +18,15 @@ function add_promo()
18 18
     ]);
19 19
 }
20 20
 
21
-function alter_promo()
21
+function alter_promo($promoid)
22 22
 {
23
-    $promo = new Promo($_POST["id"]);
23
+    $promo = new Promo($promoid);
24 24
     
25 25
     $promo->setLibelle($_POST["libelle"]);
26 26
     $promo->write();
27 27
 }
28 28
 
29
-function delete_promo()
29
+function delete_promo($promoid)
30 30
 {
31
-    (new Promo($_POST["promo"]))->erase();
31
+    (new Promo($promoid))->erase();
32 32
 }

+ 73
- 18
lib/platypuce.js Wyświetl plik

@@ -1,26 +1,81 @@
1
-var dataSelect = $("option")[0].value;
1
+var dataSelect = "";
2
+
3
+function checkPromoId(promoid)
4
+{
5
+    return promoid.match(/A[1-5]/) != null;
6
+}
7
+
8
+if($("title").text() === "Documents") {
9
+    dataSelect = $("option")[0].value;
10
+}
2 11
 
3 12
 $(document).on('change', 'select', function(e) {
4
-    dataSelect = this.options[e.target.selectedIndex].value;
13
+    if($("title").text() === "Documents") {
14
+        dataSelect = this.options[e.target.selectedIndex].value;
15
+    }
5 16
 });
6 17
 
7
-$('#addForm').submit(function(e) {
18
+$('.fa-pencil').on("click", function() {
19
+    var row = $(this).parent().parent();
20
+    var rang = $(row.children()[0]);
21
+    var rangValeur = rang.html();
22
+    rang.html('<input type="number" value="'+rangValeur+'" size="2" style="width:35px" />');
23
+    $(this).addClass("fa-check");
24
+    $(this).removeClass("fa-pencil");
25
+    $(this).off("click");
26
+    $(this).on("click", function () {
27
+        rangValeur = $(rang.children()[0]).value;
28
+        rang.html(rangValeur);
29
+    });
30
+});
8 31
 
32
+$('#addForm').submit(function(e) {
9 33
     e.preventDefault();
10 34
     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
-    });
35
+
36
+    switch ($("title").html())
37
+    {
38
+        case "Documents":
39
+            data.append("document", $("#file")[0].files[0]);
40
+            data.append("promo", dataSelect);
41
+            data.append("rang", $("#rang").val());
42
+            data.append("libelle", $("#libelle").val());
43
+
44
+            $.ajax({
45
+                method: "POST",
46
+                url: "document",
47
+                data: data,
48
+                dataType: 'json',
49
+                processData: false,
50
+                contentType: false,
51
+                complete: function (result) {
52
+
53
+                }
54
+            });
55
+            break;
56
+        case "Promotions":
57
+            if(checkPromoId($("#id").val()))
58
+            {
59
+                data.append("id", $("#id").val());
60
+                data.append("libelle", $("#libelle").val());
61
+
62
+                $.ajax({
63
+                    method: "POST",
64
+                    url: "promo",
65
+                    data: data,
66
+                    processData: false,
67
+                    contentType: false,
68
+                    complete: function (result) {
69
+                        console.log(result);
70
+                    }
71
+                });
72
+            }
73
+            else
74
+            {
75
+                var block = $(".form-group:first-child");
76
+                block.addClass("has-error");
77
+                block.html(block.html()+'<span id="helpBlock2" class="help-block">Votre identifiant doit contenir "A" suivi de l\'année correspondant à la promotion.</span>')
78
+            }
79
+            break;
80
+    }
26 81
 });

+ 26
- 4
models/data.class.php Wyświetl plik

@@ -13,13 +13,13 @@ class Data
13 13
     private $date;
14 14
     private $ip;
15 15
 
16
-    function __construct($email)
16
+    function __construct($id)
17 17
     {
18 18
         $bdd = new Connector();
19 19
 
20 20
         $data = $bdd->Select("*", "data", array(
21 21
             "where" => array(
22
-                array("identifiant", "=", $email)
22
+                array("id", "=", $id)
23 23
             )
24 24
         ));
25 25
 
@@ -31,7 +31,7 @@ class Data
31 31
         $data = $data[0];
32 32
 
33 33
         // Chargement des informations
34
-        $this->identifiant = $email;
34
+        $this->identifiant = $data["identifiant"];
35 35
         $this->nom_fils = $data["nom_fils"];
36 36
         $this->prenom_fils = $data["prenom_fils"];
37 37
         $this->ddn_fils = $data["ddn_fils"];
@@ -232,7 +232,15 @@ class Data
232 232
     public static function getAll()
233 233
     {
234 234
         $bdd = new Connector();
235
-        return $bdd->Select("*", "data");
235
+        $datas = $bdd->Select("*", "data");
236
+        $toReturn = array();
237
+
238
+        foreach ($datas as $data) {
239
+            $doc = new Data($data["id"]);
240
+            array_push($toReturn, self::toArray($doc));
241
+        }
242
+
243
+        return $toReturn;
236 244
     }
237 245
 
238 246
     function erase()
@@ -240,4 +248,18 @@ class Data
240 248
         $bdd = new Connector();
241 249
         $bdd->Delete("data", array(array("identifiant", "=", $this->identifiant)));
242 250
     }
251
+
252
+    public static function toArray($data)
253
+    {
254
+        return array(
255
+            "Identifiant" => $data->identifiant,
256
+            "Nom" => $data->nom_fils,
257
+            "Prénom" => $data->prenom_fils,
258
+            "Date de naissance" => $data->ddn_fils,
259
+            "Téléphone portable" => $data->tel_mobile,
260
+            "Adresse courriel du parent" => $data->courriel,
261
+            "Date d'enregistrement" => $data->date,
262
+            "Adresse IP" => $data->ip
263
+        );
264
+    }
243 265
 }

+ 13
- 6
models/document.class.php Wyświetl plik

@@ -63,20 +63,25 @@ class Document
63 63
         }
64 64
 
65 65
         // Determining the folder to put the document in
66
-        if (strstr($filename, "A1") || strstr($filename, "A2")) {
67
-            error_log("A1\n");
66
+        if (preg_match("/A[12]/", $options["promo"])) {
68 67
             $destination = "A12/" . $filename;
69
-        } elseif (strstr($filename, "A3") || strstr($filename, "A4") || strstr($filename, "A5")) {
70
-            error_log("A3\n");
68
+        } elseif (preg_match("/A[345]/", $options["promo"])) {
71 69
             $destination = "A345/" . $filename;
72 70
         } else {
73
-            error_log("meh\n");
74 71
             $destination = $filename;
75 72
         }
76 73
 
77 74
         error_log($destination);
78 75
 
79
-        move_uploaded_file($document["tmp_name"], __DIR__ . "../../pdf/" . $destination);
76
+        if(move_uploaded_file($document["tmp_name"], __DIR__ . "/../../pdf/" . $destination))
77
+        {
78
+            echo "Uploaded!";
79
+        }
80
+        else
81
+        {
82
+            echo ":'((((";
83
+            error_log("Error when trying to write ".__DIR__ . "/../../pdf/" . $destination);
84
+        }
80 85
 
81 86
         foreach ($options as $key => $value) {
82 87
             if (empty($value) && $key != "promo") {
@@ -90,6 +95,8 @@ class Document
90 95
             "libelle" => $options["libelle"],
91 96
             "fichier" => $destination
92 97
         ));
98
+
99
+        return $destination;
93 100
     }
94 101
 
95 102
     function erase()

+ 17
- 1
models/promo.class.php Wyświetl plik

@@ -30,7 +30,15 @@ class Promo
30 30
     public static function getAll()
31 31
     {
32 32
         $bdd = new Connector();
33
-        return $bdd->Select("*", "promo");
33
+        $promos = $bdd->Select("*", "promo");
34
+        $toReturn = array();
35
+
36
+        foreach ($promos as $promo) {
37
+            $doc = new Promo($promo["id_promo"]);
38
+            array_push($toReturn, self::toArray($doc));
39
+        }
40
+
41
+        return $toReturn;
34 42
     }
35 43
 
36 44
     /**
@@ -111,4 +119,12 @@ class Promo
111 119
             "libelle" => $promo["libelle"]
112 120
         ));
113 121
     }
122
+
123
+    public static function toArray($promo)
124
+    {
125
+        return array(
126
+            "Identifiant" => $promo->id_promo,
127
+            "Libellé" => $promo->libelle
128
+        );
129
+    }
114 130
 }

+ 2
- 3
views/layout.html.php Wyświetl plik

@@ -3,10 +3,9 @@
3 3
 <html>
4 4
     <head>
5 5
         <meta charset = "utf-8">
6
-        <title>
7
-            <?php echo $title; ?>
8
-        </title>
6
+        <title><?php echo $title; ?></title>
9 7
         <link rel="stylesheet" href="lib/bootstrap.min.css" />
8
+        <link href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet">
10 9
         <script src="lib/jquery-2.1.4.min.js"></script>
11 10
         <script src="lib/jquery.tablesorter.min.js"></script>
12 11
         <script src="lib/bootstrap.min.js"></script>

+ 41
- 16
views/list.html.php Wyświetl plik

@@ -1,40 +1,64 @@
1
-<div style="text-align:right">
1
+<?php if($title == "Documents" || $title == "Promotions")
2
+{
3
+    echo '<div style="text-align:right">
2 4
     <button class="btn btn-primary" type="button" data-toggle="collapse" data-target="#addForm" aria-expanded="false" aria-controls="addForm">
3 5
         Ajouter
4 6
     </button>
5
-</div>
7
+</div>';
8
+}
9
+?>
10
+
6 11
 
7 12
 <form class="collapse" id="addForm">
8
-    <div class="well">
13
+    <?php
14
+        switch($title)
15
+        {
16
+            case "Documents":
17
+                echo '<div class="well">
9 18
         <div class="form-group">
10 19
             <label for="promo">Promotion :</label>
11
-            <select id="promo">
12
-                <?php foreach($promos as $promo)
20
+            <select id="promo">';
21
+                foreach($promos as $promo)
13 22
                 {
14
-                    ?>
15
-                    <option value="<?php echo $promo["id_promo"]; ?>"><?php echo $promo["libelle"]; ?></option>
16
-                    <?php
23
+                    echo '<option value="'.$promo["Identifiant"].'">'.$promo["Libellé"].'</option>';
17 24
                 }
18
-                ?>
19
-                <option value=""></option>
25
+                echo '<option value=""></option>
20 26
             </select>
21 27
         </div>
22 28
         <div class="form-group">
23
-            <label for="rang">Rang :</label>
29
+            <label class="control-label" for="rang">Rang :</label>
24 30
             <input type="number" class="form-control" id="rang" />
25 31
         </div>
26 32
         <div class="form-group">
27
-            <label for="libelle">Libellé : </label>
33
+            <label class="control-label" for="libelle">Libellé : </label>
28 34
             <input type="text" class="form-control" id="libelle" placeholder="Libellé" />
29 35
         </div>
30 36
         <div class="form-group">
31
-            <label for="file">Fichier :</label>
37
+            <label class="control-label" for="file">Fichier :</label>
32 38
             <input type="file" id="file" />
33 39
         </div>
34 40
         <div class="form-group">
35 41
             <input type="submit" class="form-control" value="Ajouter le document" id="formsubmit" />
36 42
         </div>
37
-    </div>
43
+    </div>';
44
+                break;
45
+            case "Promotions":
46
+                echo '<div class="well">
47
+        <div class="form-group">
48
+            <label class="control-label" for="id">Identifiant :</label>
49
+            <input type="text" class="form-control" id="id" placeholder="Identifiant" />
50
+        </div>
51
+        <div class="form-group">
52
+            <label class="control-label" for="libelle">Libellé : </label>
53
+            <input type="text" class="form-control" id="libelle" placeholder="Libellé" />
54
+        </div>
55
+        <div class="form-group">
56
+            <input type="submit" class="form-control" value="Ajouter la promotion" id="formsubmit" />
57
+        </div>
58
+    </div>';
59
+                break;
60
+        }
61
+    ?>
38 62
 </form>
39 63
 
40 64
 <table class="table tablesorter table-striped" id="mainTable">
@@ -48,11 +72,11 @@
48 72
     <th>Opérations</th>
49 73
     </thead>
50 74
     <tbody>
51
-    <?php foreach ($data as $student) {
75
+    <?php foreach ($data as $element) {
52 76
         ?>
53 77
         <tr>
54 78
             <?php
55
-            foreach ($student as $field => $value) {
79
+            foreach ($element as $field => $value) {
56 80
                 if (is_array($value)) {
57 81
                     ?>
58 82
                     <td id="<?php echo $value["id"]; ?>"><?php echo $value["libelle"]; ?></td>
@@ -64,6 +88,7 @@
64 88
                 }
65 89
             }
66 90
             ?>
91
+            <td><i class="fa fa-pencil" style="cursor:pointer"></i></td>
67 92
         </tr>
68 93
         <?php
69 94
     }