浏览代码

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

父节点
当前提交
b4efee0d9d
共有 9 个文件被更改,包括 187 次插入54 次删除
  1. 6
    2
      controllers/document.php
  2. 5
    0
      controllers/login.php
  3. 4
    4
      controllers/promo.php
  4. 73
    18
      lib/platypuce.js
  5. 26
    4
      models/data.class.php
  6. 13
    6
      models/document.class.php
  7. 17
    1
      models/promo.class.php
  8. 2
    3
      views/layout.html.php
  9. 41
    16
      views/list.html.php

+ 6
- 2
controllers/document.php 查看文件

5
 
5
 
6
 function document()
6
 function document()
7
 {
7
 {
8
-    set("title", "Document");
8
+    set("title", "Documents");
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
-    Document::addDocument($_FILES["document"], [
17
+    $filePath = 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
+
23
+    json_encode(array(
24
+        "path" => $filePath
25
+    ));
22
 }
26
 }
23
 
27
 
24
 function delete_document($fileid)
28
 function delete_document($fileid)

+ 5
- 0
controllers/login.php 查看文件

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

+ 4
- 4
controllers/promo.php 查看文件

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
     $promo->setLibelle($_POST["libelle"]);
25
     $promo->setLibelle($_POST["libelle"]);
26
     $promo->write();
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 查看文件

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
 $(document).on('change', 'select', function(e) {
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
     e.preventDefault();
33
     e.preventDefault();
10
     var data = new FormData();
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 查看文件

13
     private $date;
13
     private $date;
14
     private $ip;
14
     private $ip;
15
 
15
 
16
-    function __construct($email)
16
+    function __construct($id)
17
     {
17
     {
18
         $bdd = new Connector();
18
         $bdd = new Connector();
19
 
19
 
20
         $data = $bdd->Select("*", "data", array(
20
         $data = $bdd->Select("*", "data", array(
21
             "where" => array(
21
             "where" => array(
22
-                array("identifiant", "=", $email)
22
+                array("id", "=", $id)
23
             )
23
             )
24
         ));
24
         ));
25
 
25
 
31
         $data = $data[0];
31
         $data = $data[0];
32
 
32
 
33
         // Chargement des informations
33
         // Chargement des informations
34
-        $this->identifiant = $email;
34
+        $this->identifiant = $data["identifiant"];
35
         $this->nom_fils = $data["nom_fils"];
35
         $this->nom_fils = $data["nom_fils"];
36
         $this->prenom_fils = $data["prenom_fils"];
36
         $this->prenom_fils = $data["prenom_fils"];
37
         $this->ddn_fils = $data["ddn_fils"];
37
         $this->ddn_fils = $data["ddn_fils"];
232
     public static function getAll()
232
     public static function getAll()
233
     {
233
     {
234
         $bdd = new Connector();
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
     function erase()
246
     function erase()
240
         $bdd = new Connector();
248
         $bdd = new Connector();
241
         $bdd->Delete("data", array(array("identifiant", "=", $this->identifiant)));
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 查看文件

63
         }
63
         }
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")) {
67
-            error_log("A1\n");
66
+        if (preg_match("/A[12]/", $options["promo"])) {
68
             $destination = "A12/" . $filename;
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
             $destination = "A345/" . $filename;
69
             $destination = "A345/" . $filename;
72
         } else {
70
         } else {
73
-            error_log("meh\n");
74
             $destination = $filename;
71
             $destination = $filename;
75
         }
72
         }
76
 
73
 
77
         error_log($destination);
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
         foreach ($options as $key => $value) {
86
         foreach ($options as $key => $value) {
82
             if (empty($value) && $key != "promo") {
87
             if (empty($value) && $key != "promo") {
90
             "libelle" => $options["libelle"],
95
             "libelle" => $options["libelle"],
91
             "fichier" => $destination
96
             "fichier" => $destination
92
         ));
97
         ));
98
+
99
+        return $destination;
93
     }
100
     }
94
 
101
 
95
     function erase()
102
     function erase()

+ 17
- 1
models/promo.class.php 查看文件

30
     public static function getAll()
30
     public static function getAll()
31
     {
31
     {
32
         $bdd = new Connector();
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
             "libelle" => $promo["libelle"]
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 查看文件

3
 <html>
3
 <html>
4
     <head>
4
     <head>
5
         <meta charset = "utf-8">
5
         <meta charset = "utf-8">
6
-        <title>
7
-            <?php echo $title; ?>
8
-        </title>
6
+        <title><?php echo $title; ?></title>
9
         <link rel="stylesheet" href="lib/bootstrap.min.css" />
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
         <script src="lib/jquery-2.1.4.min.js"></script>
9
         <script src="lib/jquery-2.1.4.min.js"></script>
11
         <script src="lib/jquery.tablesorter.min.js"></script>
10
         <script src="lib/jquery.tablesorter.min.js"></script>
12
         <script src="lib/bootstrap.min.js"></script>
11
         <script src="lib/bootstrap.min.js"></script>

+ 41
- 16
views/list.html.php 查看文件

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