summaryrefslogtreecommitdiff
path: root/Template/Include/incl_table_myMission.php
blob: 504abac1f25325577b4d2710e1100502efc0887d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
<?php

// ############################################################################
// #                                                                          #
// # Description: Tableau correspondant aux missions effectuées               #
// #              par l'utilisateur.                                          #
// #                                                                          #
// ############################################################################

// Import des textes en fonction de la langue définie dans la variable "lang" de la session.
require_once(dirname( __FILE__ )."./".$_SESSION["lang"]."/text.php");
// Import des en-tête des tables.
require_once(dirname( __FILE__ )."./".$_SESSION["lang"]."/table.php");
// Import des metodes de la base de donnée pour les recherches.
require_once(dirname( __FILE__ )."./../../Database/meth_dbsearch.php");
require_once(dirname( __FILE__ )."./../../Database/meth_dbmission.php");

// Instanciation de la bdd avec les méthodes de recherche.
$dbsearch  = new DbSearch;
$dbmission = new DbMission;
$missionStatus = [
    "pending"   => [],
    "ongoing"   => [],
    "completed" => []
];

// Recherches des missions avec l'id de l'utilisateur actuellement connecté.
switch ($_SESSION["userStatus"]) {
    case 1:
        $result = $dbmission->get_mission_by_proid($_SESSION["userId"]);
        for ($i = 0; $i < count($result); $i++) {
            $result[$i]["jobCategoryId"] = $dbsearch->get_job_by_jobid($result[$i]["jobCategoryId"]);
        }
        break;
    case 2:
        $result = $dbmission->get_mission_by_clientid($_SESSION["userId"]);
        for ($i = 0; $i < count($result); $i++) {
            $result[$i]["jobCategoryId"] = $dbsearch->get_job_by_jobid($result[$i]["jobCategoryId"]);
        }
        break;
    default:
        break;
}

// Puis on dispatch les missions dans leur categorie
for ($i = 0; $i < count($result); $i++) {
    if (!$result[$i]["acceptedByPro"]
    ) {
        array_push($missionStatus["pending"], $result[$i]);
    } elseif (!$result[$i]["validatedByPro"] 
              || !$result[$i]["validatedByClient"]
    ) {
        array_push($missionStatus["ongoing"], $result[$i]);
    } else {
        array_push($missionStatus["completed"], $result[$i]);
    }
}

// ****************************************************************************
// DIV PRINCIPALE
// ****************************************************************************
echo('<!-- Mes missions -->
<main id="mainMyMission">');

// ****************************************************************************
// BOUTTONS DE NAVIGATION
// ****************************************************************************
echo('<div id="myMissionButtons">
    <button onclick="show(\'mainMyMission\', \'section\', \'secPending\',  \'show_block\')">'.$text[basename(__FILE__, ".php")]["pendingMission"].'</button>
    <button onclick="show(\'mainMyMission\', \'section\', \'secOngoing\',  \'show_block\')">'.$text[basename(__FILE__, ".php")]["ongoingMission"].'</button>
    <button onclick="show(\'mainMyMission\', \'section\', \'secCompleted\',\'show_block\')">'.$text[basename(__FILE__, ".php")]["completedMission"].'</button>
</div>'.PHP_EOL);

// ****************************************************************************
// TABLEAU DES MISSIONS EN ATTENTE
// ****************************************************************************
if ($missionStatus["pending"]) {
    echo('<section id="secPending">
        <table>
            <!-- En-tête -->
            <tr>'.PHP_EOL);
    foreach($header["pendingMissions"] as $columnHeader) {
        echo("            <th>".$columnHeader."</th>".PHP_EOL);
    }
    echo("        </tr>".PHP_EOL);
    foreach ($missionStatus["pending"] as $rows) {
        echo('        <!-- Missions -->
            <tr>
                <td><pre>'.$rows["date"].'</pre></td>
                <td><pre>'.$rows["lastname"].'</pre></td>
                <td><pre>'.$rows["jobCategoryId"][0]["jobCategoryName".ucwords($_SESSION["lang"])].'</pre></td>
                <td><pre>'.$rows["subject"].'</pre></td>');
        if ($_SESSION["userId"] == $rows["proId"]) {
            echo('        <td class="noBorder">
                <form action="/Core/wrapper.php" method="post">
                <input type="hidden" name="acceptedMissionId" value="'.$rows["missionId"].'">
                <input type="submit" value="'.$text[basename(__FILE__, ".php")]["accept"].'">
                </form>
            </td>');
        }
        echo('            </tr>'.PHP_EOL);
    }
    echo('    </table>
    </section>');
} else {
    echo('<section id="secPending">
        <p>'.$text[basename(__FILE__, ".php")]["noPending"].'</p>
    </section>');
}

// ****************************************************************************
// TABLEAU DES MISSIONS EN COURS
// ****************************************************************************
if ($missionStatus["ongoing"]) {
    echo('<section id="secOngoing">
        <table>
            <!-- En-tête -->
            <tr>'.PHP_EOL);
    foreach($header["ongoingMissions"] as $columnHeader) {
        echo("        <th>".$columnHeader."</th>".PHP_EOL);
    }
    echo("            </tr>".PHP_EOL);
    foreach ($missionStatus["ongoing"] as $rows) {
        echo('        <!-- Missions -->
            <tr>
                <td><pre>'.$rows["acceptedByPro"].'</pre></td>
                <td><pre>'.$rows["lastname"].'</pre></td>
                <td><pre>'.$rows["jobCategoryId"][0]["jobCategoryName".ucwords($_SESSION["lang"])].'</pre></td>
                <td><pre>'.$rows["subject"].'</pre></td>
                <td><pre>'.$rows["validatedByClient"].'</pre></td>
                <td><pre>'.$rows["validatedByPro"].'</pre></td>');
        if (!$rows["validatedByClient"] && $_SESSION["userStatus"] == 2 
            || (!$rows["validatedByPro"] && $_SESSION["userStatus"] == 1)
        ) {
            echo('            <td class="noBorder">
                    <form action="/Core/wrapper.php" method="post">
                    <input type="hidden" name="validatedMissionId" value="'.$rows["missionId"].'">
                    <input type="submit" value="'.$text[basename(__FILE__, ".php")]["validate"].'">
                    </form>
                </td>');
        }
        echo('        </tr>'.PHP_EOL);
    }
    echo('    </table>
    </section>');
} else {
    echo('<section id="secOngoing">
        <p>'.$text[basename(__FILE__, ".php")]["noOngoing"].'</p>
    </section>');
}

// ****************************************************************************
// TABLEAU DES MISSIONS TERMINEES
// ****************************************************************************
if ($missionStatus["completed"]) {
    echo('<section id="secCompleted">
        <table>
            <!-- En-tête -->
            <tr>'.PHP_EOL);
    foreach($header["completedMissions"] as $columnHeader) {
        echo("            <th>".$columnHeader."</th>".PHP_EOL);
    }
    echo("        </tr>".PHP_EOL);
    foreach ($missionStatus["completed"] as $rows) {
        echo('        <!-- Missions -->
            <tr>
                <td><pre>'.$rows["date"].'</pre></td>
                <td><pre>'.$rows["acceptedByPro"].'</pre></td>
                <td><pre>'.$rows["validatedByClient"].'</pre></td>
                <td><pre>'.$rows["validatedByPro"].'</pre></td>
                <td><pre>'.$rows["lastname"].'</pre></td>
                <td><pre>'.$rows["jobCategoryId"][0]["jobCategoryName".ucwords($_SESSION["lang"])].'</pre></td>
                <td><pre>'.$rows["subject"].'</pre></td>');
        if ($rows["review"]) {
            echo('<td><pre>'.$rows["review"].'</pre></td>');
        } else {
            echo('<td><pre>N/A</pre></td>');
        }
        if ($rows["note"]) {
            echo('<td><pre>'.$rows["note"].'</pre></td>');
        } else {
            echo('<td><pre>N/A</pre></td>');
        }
            echo('</tr>'.PHP_EOL);
    }
    echo('    </table>
    </section>');
} else {
    echo('<section id="secCompleted">
        <p>'.$text[basename(__FILE__, ".php")]["noCompleted"].'</p>
    </section>');
}

echo('<!-- Espace vide si le tableau est petit -->
<div class="spacer"></div>');

// ****************************************************************************
// FIN DIV PRINCIPALE
// ****************************************************************************
echo('</main>'.PHP_EOL);

?>