container.php 12.7 KB
Newer Older
jlopez's avatar
jlopez committed
1
2
3
4
5
6
7
8
9
<?php


session_start ();

require_once "./dao/DBquery.php";

$db = new DBquery();

jlopez's avatar
jlopez committed
10
11
12
13
14
15
16
17
18
$type = "all";
$author = NULL;
$labels = array();
$tags = array();
$descriptions = array();

if(isset($_GET['type'])) {
    $type = $_GET['type'];
}
jlopez's avatar
jlopez committed
19

jlopez's avatar
jlopez committed
20
21
22
if(isset($_GET['mycontainer'])) {
    $author = $_SESSION['username'];
}
23

jlopez's avatar
jlopez committed
24
25
26
27
28
if(isset($_GET['labels'])) {
    foreach( $_GET['labels'] as $n) {
        array_push($labels, $n);
    }
}
29

jlopez's avatar
jlopez committed
30
31
32
33
34
35
36
37
38
if(isset($_GET['tags'])) {
    $tags = explode(" ", $_GET['tags']);
}

if(isset($_GET['descriptions'])) {
    $descriptions = explode(" ", $_GET['descriptions']);
}

$containers = $db->getContainers($type, $author, $labels, $tags, $descriptions);
jlopez's avatar
jlopez committed
39

jlopez's avatar
jlopez committed
40
require_once "./inc/php/buildHeader.php";
jlopez's avatar
jlopez committed
41
?>
jlopez's avatar
jlopez committed
42
43
44

<div class="container-fluid">

jlopez's avatar
jlopez committed
45
    <br/><br/>
46

jlopez's avatar
jlopez committed
47
48
49
50
    <div class="row justify-content-md-center text-center">
        <div class="col-sm-2">
            <div class="card border-primary sm-2">
            <div class="card-header font-weight-bold text-white bg-primary"><h4>Docker public</h4></div>
51
            <div class="card-body text-primary">
jlopez's avatar
jlopez committed
52
                <h5 class="card-title"><?php echo $db->getNumberDockerContainer() ?> Files</h5>
53
54
55
            </div>
            </div>
        </div>
jlopez's avatar
jlopez committed
56
57
58
        <div class="col-sm-2">
            <div class="card border-success sm-2">
            <div class="card-header font-weight-bold text-white bg-success"><h4>Singularity public</h4></div>
59
            <div class="card-body text-success">
jlopez's avatar
jlopez committed
60
                <h5 class="card-title"><?php echo $db->getNumberSingularityContainer() ?> Files</h5>      
61
62
63
            </div>
            </div>
        </div>
jlopez's avatar
jlopez committed
64
    </div>
65

jlopez's avatar
jlopez committed
66
67
68
69
    <br/><br/>

    <div class="row">

jlopez's avatar
jlopez committed
70
71
72
73
74
75
76
77
78
79
80
81
    <div id="accordion">
        <div class="card">
            <div class="card-header" id="headingOne">
                <h5 class="mb-0">
                    <button class="btn btn-info" data-toggle="collapse" data-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
                    Filter
                    </button>
                    <a href="./container.php" class="btn btn-success">
                    Reset
                    </a>
                </h5>
            </div>
jlopez's avatar
jlopez committed
82

jlopez's avatar
jlopez committed
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
            <div id="collapseOne" class="collapse" aria-labelledby="headingOne" data-parent="#accordion">
                <div class="card-body col-12">
                    <form method="get">
                        <div class="form-inline form-group">
                            <label for="containerType">Container type :</label>
                            <div class="form-check">
                                <input class="form-check-input" type="radio" name="type" id="containerType0" value="All" checked>
                                <label class="form-check-label" for="containerType0">
                                    All
                                </label>
                            </div>
                            <div class="form-check">
                                <input class="form-check-input" type="radio" name="type" id="containerType1" value="Singularity">
                                <label class="form-check-label" for="containerType1">
                                    Singularity
                                </label>
                            </div>
                            <div class="form-check">
                                <input class="form-check-input" type="radio" name="type" id="containerType2" value="Docker">
                                <label class="form-check-label" for="containerType2">
                                    Docker
                                </label>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="labels">Labels :</label>
                            <select multiple class="form-control col-12" id="labels[]" name="labels[]">
                           
                            <?php
                                foreach ($db->getLabels() as $label) {
                                   echo '<option value="'.$label->ID.'">'.$label->name.'</option>';
                                }
                            ?>
                            </select>
                            <small id="emailHelp" class="form-text text-muted">Multiple choises is possible.</small>
                        </div>
                        <div class="form-group">
                            <label for="tags">Tags :</label>
                            <input type="text" class="form-control" id="tags" name="tags">
                        </div>
                        <div class="form-group">
                            <label for="tags">Description :</label>
                            <input type="text" class="form-control" id="descriptions" name="descriptions">
                        </div>
jlopez's avatar
jlopez committed
127
                        <?php
jlopez's avatar
jlopez committed
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
                            if(isset($_SESSION['username'])) {
                                echo '
                                <div class="form-check">
                                    <input type="checkbox" class="form-check-input" id="mycontainer" name="mycontainer">
                                    <label class="form-check-label" for="mycontainer">Only my containers</label>
                                    <br/><br/>
                                </div>
                                ';
                            }
                        ?>
                        <div class="form-inline form-group">
                            <label for="containerType">Order by :</label>
                            <div class="form-check">
                                <input type="radio" class="form-check-input" id="order" name="order" checked>
                                <label class="form-check-label" for="order">Date</label>
                                <br/><br/>
                            </div>
                        </div>
                        <div class="form-group">
                            <button type="submit" class="btn btn-primary">Find</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
jlopez's avatar
jlopez committed
154

jlopez's avatar
jlopez committed
155
    </div>
jlopez's avatar
jlopez committed
156

jlopez's avatar
jlopez committed
157
    <br/><br/>
jlopez's avatar
jlopez committed
158

jlopez's avatar
jlopez committed
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
    <div class="row">
        <div class="col-12">
            <table id="Table_Container" class="table table-striped table-bordered">
                <thead>
                    <tr>
                        <th>Name</th>
                        <th>Author</th>
                        <th>Labels</th>
                        <th>Tags</th>
                        <th>Date</th>
                        <th>Description</th>
                        <th>Action</th>
                    </tr>
                </thead>
                <tbody id="TableSection">
                <?php

                    foreach ($containers as $container) {

                        $container->escape2($db);

                        $visibility = "private";
                        $colorV = "e67e22";


                        if($container->visibility) {
                            $visibility = "public";
                            $colorV = "f1c40f";
                        }

                        if(!$container->visibility) {
                            if($container->author != $_SESSION['username']) {
                                if($db->getGradeWithLogin($_SESSION['username'])->name != $db->getMaxGrades()->name) {
                                    continue;
                                }
                            }
                        }
jlopez's avatar
jlopez committed
196

jlopez's avatar
jlopez committed
197
198
                        $typeC = "docker";
                        $colorT = "007bff";
jlopez's avatar
jlopez committed
199

jlopez's avatar
jlopez committed
200
201
202
203
                        if($container->type == "Singularity") {
                            $typeC = "singularity";
                            $colorT = "28a745";
                        }
jlopez's avatar
jlopez committed
204

jlopez's avatar
jlopez committed
205
206
207
                        echo '<tr>';
                        echo '<td>' . $container->name . '</td>';
                        echo '<td>' . $container->author . '</td>';
jlopez's avatar
jlopez committed
208

jlopez's avatar
jlopez committed
209

jlopez's avatar
jlopez committed
210
                        $labels = $db->getLabelWithContainerId($container->ID);
jlopez's avatar
jlopez committed
211

jlopez's avatar
jlopez committed
212
213
214
                        echo '<td>';
                        echo '<span class="badge" style="background:#'.$colorT.'">'.$typeC.'</span>';
                        echo '<span class="badge" style="background:#'.$colorV.'">'.$visibility.'</span>';
jlopez's avatar
jlopez committed
215

jlopez's avatar
jlopez committed
216
                        echo '<br/>';
jlopez's avatar
jlopez committed
217

jlopez's avatar
jlopez committed
218
                        $index = 0;
jlopez's avatar
jlopez committed
219

jlopez's avatar
jlopez committed
220
221
                        foreach ($labels as $label) {
                            echo '<span class="badge" style="background:#'.$label->color.'">'.$label->name.'</span>';
jlopez's avatar
jlopez committed
222

jlopez's avatar
jlopez committed
223
                            if($index == 1) {
jlopez's avatar
jlopez committed
224
225
                                echo '<br/>';
                                $index = 0;
jlopez's avatar
jlopez committed
226
227
228
229
230
231
                            } else {
                                $index++;
                            }       
                        }
                        
                        echo '</td>';
jlopez's avatar
jlopez committed
232

jlopez's avatar
jlopez committed
233
                        $tags = explode( ' ', $container->tags );
jlopez's avatar
jlopez committed
234

jlopez's avatar
jlopez committed
235
                        $index = 0;
jlopez's avatar
jlopez committed
236

jlopez's avatar
jlopez committed
237
                        echo '<td>';
jlopez's avatar
jlopez committed
238

jlopez's avatar
jlopez committed
239
240
241
                        foreach ($tags as $tag) {
                            echo '<span class="badge" style="background:#'."30336b".'; color:#FFFFFF">'.$tag.'</span>';  
                        }
jlopez's avatar
jlopez committed
242

jlopez's avatar
jlopez committed
243
244
245
                        echo  '</td>';
                        echo '<td>' . $container->date . '</td>';
                        echo '<td>' . $container->description . '</td>';
jlopez's avatar
jlopez committed
246

jlopez's avatar
jlopez committed
247
                        echo '<td>';
jlopez's avatar
jlopez committed
248

jlopez's avatar
jlopez committed
249
                        echo '<div class="btn-group mr-1" ><button class="btn btn-success btn-sm" onclick="showFileContainer(\''.$container->ID.'\')">show</button></div>';
jlopez's avatar
jlopez committed
250

jlopez's avatar
jlopez committed
251
                        echo '<div class="btn-group mr-1" ><a class="btn btn-primary btn-sm" href="./action/action_container.php?action=download&containerid='.$container->ID.'">dowload</a></div>';
jlopez's avatar
jlopez committed
252

jlopez's avatar
jlopez committed
253
254
255
                        if($container->author == $_SESSION['username'] || $_SESSION['manage'] ) {
                            //echo '<div class="btn-group mr-1"><a class="btn btn-warning btn-sm" href="./action/action_container.php?action=update&containerid='.$container->ID.'" >update</a></div>';
                        }
jlopez's avatar
jlopez committed
256

jlopez's avatar
jlopez committed
257
258
259
260
261
262
263
264
                        if($container->author == $_SESSION['username'] || $_SESSION['manage'] ) {
                            echo '<div class="btn-group mr-1"><a class="btn btn-danger btn-sm" href="./action/action_container.php?action=delete&containerid='.$container->ID.'" >delete</a></div>';
                        }
                        
            
                        echo '</td>';
                        echo '</tr>';
                    }
jlopez's avatar
jlopez committed
265

jlopez's avatar
jlopez committed
266
                ?>
jlopez's avatar
jlopez committed
267

jlopez's avatar
jlopez committed
268
269
270
                </tbody>
            </table>
        </div>
jlopez's avatar
jlopez committed
271
272
    </div>

jlopez's avatar
jlopez committed
273
    <!-- Start Modal Publish -->
274
    <div class="modal" id="modalShowContainer">
jlopez's avatar
jlopez committed
275
        <div class="modal-dialog modal-xl">
276
277
            <div class="modal-content modal-xl">
                <div class="modal-header">
jlopez's avatar
jlopez committed
278
279
                    <h4 class="modal-title">Container file</h4>
                    <button type="button" class="close" data-dismiss="modal">&times;</button>
280
                </div>
jlopez's avatar
jlopez committed
281
                <div class="modal-body">
282
                    <textarea type="text" class="form-control" id="valueContainerFile" name="value" value=""></textarea>
jlopez's avatar
jlopez committed
283
284
                </div>
                <div class="modal-footer">
jlopez's avatar
jlopez committed
285
                    <button type="submit" class="btn btn-success">Import</button>
286
                    <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
jlopez's avatar
jlopez committed
287
                </div>
288
            </div>
jlopez's avatar
jlopez committed
289
290
291
        </div>
    </div>  
    <!-- End Modal Publish -->
292

jlopez's avatar
jlopez committed
293
294
295
296
    <br/><br/><br/><br/><br/><br/>

</div>

297
298
299
300
301
302
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"  crossorigin="anonymous"></script>


jlopez's avatar
jlopez committed
303
<script type="text/javascript">
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319

function showFileContainer(id ) {
    var value = FILE_CONTAINER[id];

    document.getElementById('valueContainerFile').value = value;

    var size = value.split(/\r\n|\r|\n/).length;

    document.getElementById("valueContainerFile").rows = size; 

    $('#modalShowContainer').modal();
}

var FILE_CONTAINER = [];

$(function()
jlopez's avatar
jlopez committed
320
321
322
323
324
325
326
327
{
    <?php
        foreach ($containers as $container) {
            echo 'FILE_CONTAINER["'.$container->ID.'"] = "'.$container->value.'";
            ';
        }
    ?>
});
328

jlopez's avatar
jlopez committed
329
330
331
332
333
</script>

</body>

</html>