DBquery.php 21 KB
Newer Older
jlopez's avatar
jlopez committed
1
2
3
4
5
6
7
8
<?php
/**
 * Created by PhpStorm.
 * User: jimmy
 * Date: 29/01/19
 * Time: 16:38
 */

remy's avatar
remy committed
9
require_once(__DIR__.'/../inc/conf/Conf.php');
jlopez's avatar
jlopez committed
10
11
12
require_once(__DIR__.'/../model/Section.php');
require_once(__DIR__.'/../model/Manager.php');
require_once(__DIR__.'/../model/Distribution.php');
jlopez's avatar
jlopez committed
13
require_once(__DIR__.'/../model/Package.php');
jlopez's avatar
jlopez committed
14
require_once(__DIR__.'/../model/Container.php');
jlopez's avatar
jlopez committed
15
16
17
18
require_once(__DIR__.'/../model/Grade.php');
require_once(__DIR__.'/../model/Label.php');
require_once(__DIR__.'/../model/User.php');
require_once(__DIR__.'/../model/ContainerLabel.php');
jlopez's avatar
Fix #7    
jlopez committed
19
require_once(__DIR__.'/../model/Config.php');
jlopez's avatar
jlopez committed
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

class DBquery
{

    var $dbh = NULL;

    public function __construct() {
        $this->openConnection();
    }

    /**
     * For open a database connection
     **/
    public function openConnection() {
        $this->dbh = mysqli_connect(Conf::$DB_HOSTNAME, conf::$DB_USERNAME, Conf::$DB_PP, Conf::$DB_NAME);

        if(!$this->dbh){
            die('Could not connect: ' . mysqli_error($this->dbh));
        }

        if (mysqli_connect_errno()) {
            printf("Echec connection : %s\n", mysqli_connect_error());
            exit();
        }
    }

    /**
     * Escapes special characters in a string for use in an SQL statement
     * @param string $value
     * @return string
     */
    public function escape($value) {
        return mysqli_real_escape_string($this->dbh, $value);
    }

jlopez's avatar
jlopez committed
55
56
57
58
59
    /**
     * Get all Distributions
     * 
     * @return array
     */
jlopez's avatar
jlopez committed
60
    public function getDistributions() {
jlopez's avatar
jlopez committed
61
62
63
64
        $sql = "SELECT * FROM `Distrib` ORDER BY `Distrib`.`name` ASC;";
        $result = mysqli_query($this->dbh, $sql);
        $results = array();
        while($row = mysqli_fetch_assoc($result)){
jlopez's avatar
jlopez committed
65
            $d = new Distribution($row['ID'], $row['name'], $row['version'], $row['manager'], $row['active'], $row['vname']);
jlopez's avatar
jlopez committed
66
            array_push($results, $d);
jlopez's avatar
jlopez committed
67
68
69
70
        }
        return $results;
    }

jlopez's avatar
jlopez committed
71
72
73
74
75
76
77
78
    /**
     * Get distribution vname with name and version
     * 
     * @param string $name The name of the distribution to find
     * @param string $version The version of the distribution to find
     * 
     * @return string
     */
jlopez's avatar
jlopez committed
79
80
81
82
83
84
85
86
87
    public function getVName($name, $version) {
        $sql = "SELECT vname  FROM `Distrib` WHERE active = 1 AND `name`='$name' AND `version`='$version';";
        $result = mysqli_query($this->dbh, $sql);
        while($row = mysqli_fetch_assoc($result)){
            return $row['vname'];
        }
        return "";
    }

jlopez's avatar
jlopez committed
88
89
90
91
92
    /**
     * Get all active distributions
     * 
     * @return array
     */
jlopez's avatar
jlopez committed
93
94
95
96
97
    public function getActiveDistributions() {
        $sql = "SELECT * FROM `Distrib` WHERE active = 1 ORDER BY `Distrib`.`name` ASC;";
        $result = mysqli_query($this->dbh, $sql);
        $results = array();
        while($row = mysqli_fetch_assoc($result)){
jlopez's avatar
jlopez committed
98
            $d = new Distribution($row['ID'], $row['name'], $row['version'], $row['manager'], $row['active'], $row['vname']);
jlopez's avatar
jlopez committed
99
100
101
102
103
            array_push($results, $d);
        }
        return $results;
    }

jlopez's avatar
jlopez committed
104
105
106
107
108
    /**
     * Get all full name from all active distributions
     * 
     * @return array
     */
jlopez's avatar
jlopez committed
109
    public function getActiveDistributionsFullName() {
jlopez's avatar
jlopez committed
110
        $sql = "SELECT name,version,vname  FROM `Distrib` WHERE active = 1 ORDER BY `Distrib`.`name` ASC;";
jlopez's avatar
jlopez committed
111
112
113
114
115
116
117
118
        $result = mysqli_query($this->dbh, $sql);
        $results = array();
        while($row = mysqli_fetch_assoc($result)){
            array_push($results, $row['name'].":".$row['version']);
        }
        return $results;
    }

jlopez's avatar
jlopez committed
119
120
121
122
123
    /**
     * Get all managers
     * 
     * @return array
     */
jlopez's avatar
jlopez committed
124
    public function getManagers() {
jlopez's avatar
jlopez committed
125
        $sql = "SELECT * FROM `Manager`;";
jlopez's avatar
jlopez committed
126
127
128
        $result = mysqli_query($this->dbh, $sql);
        $results = array();
        while($row = mysqli_fetch_assoc($result)){
jlopez's avatar
jlopez committed
129
130
            $m = new Manager($row['ID'], $row['name'], $row['value']);
            array_push($results, $m);
jlopez's avatar
jlopez committed
131
132
133
134
        }
        return $results;
    }

jlopez's avatar
jlopez committed
135
136
137
138
139
    /**
     * Get all users
     * 
     * @return array
     */
jlopez's avatar
jlopez committed
140
141
142
143
144
145
146
147
148
149
150
    public function getUsers() {
        $sql = "SELECT * FROM `User`;";
        $result = mysqli_query($this->dbh, $sql);
        $results = array();
        while($row = mysqli_fetch_assoc($result)){
            $u = new User($row['ID'], $row['login'], $row['gradeId']);
            array_push($results, $u);
        }
        return $results;
    }

jlopez's avatar
jlopez committed
151
152
153
154
155
156
157
    /**
     * Get grade with user login
     * 
     * @param string $login The login of ther user
     * 
     * @return array
     */
jlopez's avatar
jlopez committed
158
159
160
161
162
163
164
165
166
167
168
169
    public function getGradeWithLogin($login) {
        $sql = "SELECT * FROM `User` WHERE `login` = '$login';";
        $result = mysqli_query($this->dbh, $sql);

        while($row = mysqli_fetch_assoc($result)){
            $u = new User($row['ID'], $row['login'], $row['gradeId']);
            return $this->getGradeWithId($u->gradeId);
        }
  
        return $this->getLowerGrades();
    }

jlopez's avatar
jlopez committed
170
171
172
173
174
175
176
    /**
     * Get all labels for specific grade
     * 
     * @param $string $grade The grade to find the labels
     * 
     * @return array
     */
jlopez's avatar
jlopez committed
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
    public function getLabelsWithGrade($grade) {

        $labels = $this->getLabels();

        $results = array();

        foreach ($labels as $label){ 

            $grd = $this->getGradeWithId($label->gradeId);

            if($grd->level >= $grade->level) {
                array_push($results, $label);
            }

        }

        return $results;
    }

jlopez's avatar
jlopez committed
196
197
198
199
200
    /**
     * Get all grades
     * 
     * @return array
     */
jlopez's avatar
jlopez committed
201
202
203
204
205
206
207
208
209
210
211
    public function getGrades() {
        $sql = "SELECT * FROM `Grade` ORDER BY `level` ASC;";
        $result = mysqli_query($this->dbh, $sql);
        $results = array();
        while($row = mysqli_fetch_assoc($result)){
            $m = new Grade($row['ID'], $row['name'], $row['level']);
            array_push($results, $m);
        }
        return $results;
    }

jlopez's avatar
jlopez committed
212
213
214
215
216
    /**
     * Get all configs
     * 
     * @return array
     */
jlopez's avatar
Fix #7    
jlopez committed
217
218
219
220
221
222
223
224
225
226
227
    public function getConfigs() {
        $sql = "SELECT * FROM `Config` WHERE 1;";
        $result = mysqli_query($this->dbh, $sql);
        $results = array();
        while($row = mysqli_fetch_assoc($result)){
            $cfg = new Config($row['ID'], $row['type'], $row['description'], $row['value'], $row['active']);
            array_push($results, $cfg);
        }
        return $results;  
    }

jlopez's avatar
jlopez committed
228
229
230
231
232
233
234
    /**
     * Gel all active config with type
     * 
     * @param string $type The type of the config
     * 
     * @return array
     */
jlopez's avatar
Fix #7    
jlopez committed
235
236
237
238
239
240
241
242
243
244
245
    public function getActiveConfigsWithType($type) {
        $sql = "SELECT * FROM `Config` WHERE `type`='$type' AND `active` = 1;";
        $result = mysqli_query($this->dbh, $sql);
        $results = array();
        while($row = mysqli_fetch_assoc($result)){
            $cfg = new Config($row['ID'], $row['type'], $row['description'], $row['value'], $row['active']);
            array_push($results, $cfg);
        }
        return $results;  
    }

jlopez's avatar
jlopez committed
246
247
248
249
250
251
252
    /**
     * Get grade with this ID
     * 
     * @param int $ID The ID of the grade
     * 
     * @return Grade
     */
jlopez's avatar
jlopez committed
253
254
255
256
257
258
259
260
261
262
263
    public function getGradeWithId($ID) {
        $sql = "SELECT * FROM `Grade` WHERE `ID` = '$ID';";
        $result = mysqli_query($this->dbh, $sql);
        $results = array();
        while($row = mysqli_fetch_assoc($result)){
            $m = new Grade($row['ID'], $row['name'], $row['level']);
            return $m;
        }
        return $results;
    }

jlopez's avatar
jlopez committed
264
265
266
267
268
    /**
     * Get lower grade
     * 
     * @return Grade
     */
jlopez's avatar
jlopez committed
269
270
271
272
273
274
    public function getLowerGrades() {
        $sql = "SELECT * FROM `Grade` ORDER BY `level` DESC LIMIT 1;";
        $result = mysqli_query($this->dbh, $sql);
        $results = array();
        while($row = mysqli_fetch_assoc($result)){
            $m = new Grade($row['ID'], $row['name'], $row['level']);
jlopez's avatar
jlopez committed
275
276
277
278
279
            return $m;
        }
        return $results;
    }

jlopez's avatar
jlopez committed
280
281
282
283
284
    /**
     * Get max grade
     * 
     * @return Grade
     */
jlopez's avatar
jlopez committed
285
286
287
288
289
290
291
    public function getMaxGrades() {
        $sql = "SELECT * FROM `Grade` ORDER BY `level` ASC LIMIT 1;";
        $result = mysqli_query($this->dbh, $sql);
        $results = array();
        while($row = mysqli_fetch_assoc($result)){
            $m = new Grade($row['ID'], $row['name'], $row['level']);
            return $m;
jlopez's avatar
jlopez committed
292
293
294
        }
        return $results;
    }
jlopez's avatar
jlopez committed
295
296
297
298
299
300
    
    /**
     * Get all public tags
     * 
     * @return array
     */
jlopez's avatar
jlopez committed
301
302
303
304
305
306
307
308
309
310
    public function getAllPublicTags() {
        $sql = "SELECT tags FROM `Container` WHERE tags <> '' AND visibility = 1;";
        $result = mysqli_query($this->dbh, $sql);
        $results = array();
        while($row = mysqli_fetch_assoc($result)){
            array_push($results, $row['tags']);
        }
        return $results;
    }

jlopez's avatar
jlopez committed
311
312
313
314
315
316
317
318
319
320
321
322
    /**
     * Get all containers
     * 
     * @param string $type
     * @param string $author
     * @param array $labels
     * @param array $tags
     * @param string $description 
     * 
     * @return array
     * 
     */
jlopez's avatar
jlopez committed
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
    public function getContainers($type, $author, $labels, $tags, $descriptions) {
        $sql = "SELECT * FROM `Container`";

        if($type == "Singularity" || $type == "Docker") {
            $sql .= " WHERE `type` = '$type'";
        } else {
            $sql .= " WHERE 1";
        }

        if($author != NULL) {
            $sql .= " AND `author` = '$author'";
        }

        if(sizeof($labels) > 0) {
            $subsql = "(SELECT DISTINCT containerId FROM `ContainerLabel` WHERE labelId IN (";

            $index = 0;
            
            foreach ($labels as $label) {
                if($index != 0) {
                    $subsql .= ","; 
                } 

                $subsql .= $label;

                $index++;
            }
            $subsql .= "))";

            $sql .= " AND ID IN " . $subsql;
        }

        if(sizeof($tags) > 0) {
            foreach ($tags as $tag) {
                $sql .= " AND tags LIKE '%".$tag."%'";
            }
        }

        if(sizeof($descriptions) > 0) {
            foreach ($descriptions as $d) {
                $sql .= " AND description LIKE '%".$d."%'";
            }
        }

        $sql .= " ORDER BY `Container`.`date` DESC;";
        
jlopez's avatar
jlopez committed
369
370
371
        $result = mysqli_query($this->dbh, $sql);
        $results = array();
        while($row = mysqli_fetch_assoc($result)){
jlopez's avatar
jlopez committed
372
            $cnt = new Container($row['ID'], $row['name'], $row['value'], $row['type'], $row['visibility'], $row['description'], $row['author'], $row['date'], $row['tags']);
jlopez's avatar
jlopez committed
373
374
375
376
377
            array_push($results, $cnt);
        }
        return $results;
    }

jlopez's avatar
jlopez committed
378
379
380
381
382
383
384
    /**
     * Get container with this id
     * 
     * @param int $id The id of the container
     * 
     * @return Container
     */
jlopez's avatar
jlopez committed
385
386
387
388
389
390
391
392
393
394
395
    public function getContainerWithId($id) {
        $sql = "SELECT * FROM `Container` WHERE `ID` = '$id';";
        $result = mysqli_query($this->dbh, $sql);
        $results = array();
        while($row = mysqli_fetch_assoc($result)){
            $cnt = new Container($row['ID'], $row['name'], $row['value'], $row['type'], $row['visibility'], $row['description'], $row['author'], $row['date']);
            return $cnt;
        }
        return $results;
    }

jlopez's avatar
jlopez committed
396
397
398
399
400
    /**
     * Get all labels
     * 
     * @return array
     */
jlopez's avatar
jlopez committed
401
402
403
404
405
406
407
408
409
410
411
    public function getLabels() {
        $sql = "SELECT * FROM `Label`;";
        $result = mysqli_query($this->dbh, $sql);
        $results = array();
        while($row = mysqli_fetch_assoc($result)){
            $l = new Label($row['ID'], $row['name'], $row['color'], $row['gradeId']);
            array_push($results, $l);
        }
        return $results;
    }

jlopez's avatar
jlopez committed
412
413
414
415
416
417
418
419
    /**
     * Get label with this id
     * 
     * @param int $id The id of the label
     * 
     * @return Label
     * 
     */
jlopez's avatar
jlopez committed
420
421
422
423
424
425
426
427
428
429
430
    public function getLabelsWithId($id) {
        $sql = "SELECT * FROM `Label` WHERE `ID` = $id;";
        $result = mysqli_query($this->dbh, $sql);
        $results = array();
        while($row = mysqli_fetch_assoc($result)){
            $l = new Label($row['ID'], $row['name'], $row['color'], $row['gradeId']);
            return $l;
        }
        return $results;
    }

jlopez's avatar
jlopez committed
431
432
433
434
435
436
437
    /**
     * Get all labels for Container
     * 
     * @param int $id The id of the container
     * 
     * @return array
     */
jlopez's avatar
jlopez committed
438
439
440
441
442
443
444
445
446
447
448
    public function getLabelWithContainerId($id) {
        $sql = "SELECT * FROM `ContainerLabel` WHERE `containerId` = $id";
        $result = mysqli_query($this->dbh, $sql);
        $results = array();
        while($row = mysqli_fetch_assoc($result)){
            $l = $this->getLabelsWithId($row['labelId']);
            array_push($results, $l);
        }
        return $results;
    }

jlopez's avatar
jlopez committed
449
450
451
452
453
    /**
     * Get all active Section who is parent
     * 
     * @return array
     */
jlopez's avatar
jlopez committed
454
455
456
457
458
459
460
461
462
463
464
    public function getAllActiveSectionParent() {
        $sql = "SELECT * FROM `Section` WHERE `Section`.`parent` IS NULL AND active = 1 ORDER BY `Section`.`arrangement` ASC;";
        $result = mysqli_query($this->dbh, $sql);
        $results = array();
        while($row = mysqli_fetch_assoc($result)){
            $s = new Section($row['ID'], $row['name'], $row['visual'], $row['active'], $row['color'], $row['arrangement'], $row['parent']);
            array_push($results,$s);
        }
        return $results;
    }

jlopez's avatar
jlopez committed
465
466
467
468
469
    /**
     * Get all section parent
     * 
     * @return array
     */
jlopez's avatar
jlopez committed
470
    public function getAllSectionParent() {
jlopez's avatar
jlopez committed
471
472
473
474
        $sql = "SELECT * FROM `Section` WHERE `Section`.`parent` IS NULL ORDER BY `Section`.`arrangement` ASC;";
        $result = mysqli_query($this->dbh, $sql);
        $results = array();
        while($row = mysqli_fetch_assoc($result)){
jlopez's avatar
jlopez committed
475
            $s = new Section($row['ID'], $row['name'], $row['visual'], $row['active'], $row['color'], $row['arrangement'], $row['parent']);
jlopez's avatar
jlopez committed
476
            array_push($results,$s);
jlopez's avatar
jlopez committed
477
478
479
480
        }
        return $results;
    }

jlopez's avatar
jlopez committed
481
482
483
484
485
486
487
    /**
     * Get all active Section for specific parent
     * 
     * @param string $parent The name of the parent
     * 
     * @return array
     */
jlopez's avatar
jlopez committed
488
    public function getSectionWhithParent($parent) {
jlopez's avatar
jlopez committed
489
        $sql = "SELECT * FROM `Section` WHERE `Section`.`parent` = '$parent' AND active = 1 ORDER BY `Section`.`arrangement` ASC;";
jlopez's avatar
jlopez committed
490
491
492
        $result = mysqli_query($this->dbh, $sql);
        $results = array();
        while($row = mysqli_fetch_assoc($result)){
jlopez's avatar
jlopez committed
493
            array_push($results,array($row['name'], $row['visual'], $row['active'], $row['color']));
jlopez's avatar
jlopez committed
494
495
496
497
        }
        return $results;
    }

jlopez's avatar
jlopez committed
498
499
500
501
502
503
    /**
     * 
     * Get all name of the section who have a parent
     * 
     * @return array
     */
jlopez's avatar
jlopez committed
504
505
506
507
508
509
510
511
512
513
    public function getNameSectionWhithParent($parent) {
        $sql = "SELECT name FROM `Section` WHERE `Section`.`parent` = '$parent' AND active = 1 ORDER BY `Section`.`arrangement` ASC;";
        $result = mysqli_query($this->dbh, $sql);
        $results = array();
        while($row = mysqli_fetch_assoc($result)){
            array_push($results,$row['name']);
        }
        return $results;
    }

jlopez's avatar
jlopez committed
514
515
516
517
518
519
520
   /**
     * Get all Section for specific parent
     * 
     * @param string $parent The name of the parent
     * 
     * @return array
     */
jlopez's avatar
jlopez committed
521
522
523
524
525
    public function getAllSectionWhithParent($parent) {
        $sql = "SELECT * FROM `Section` WHERE `Section`.`parent` = '$parent' ORDER BY `Section`.`arrangement` ASC;";
        $result = mysqli_query($this->dbh, $sql);
        $results = array();
        while($row = mysqli_fetch_assoc($result)){
jlopez's avatar
jlopez committed
526
527
528
529
530
531
            $s = new Section($row['ID'], $row['name'], $row['visual'], $row['active'], $row['color'], $row['arrangement'], $row['parent']);
            array_push($results,$s);
        }
        return $results;
    }

jlopez's avatar
jlopez committed
532
533
534
535
536
537

    /**
     * Get all action section
     * 
     * @return array
     */
jlopez's avatar
jlopez committed
538
539
540
541
542
543
    public function getActiveSection() {
        $sql = "SELECT * FROM `Section` WHERE active = 1 ORDER BY `Section`.`arrangement` ASC;";
        $result = mysqli_query($this->dbh, $sql);
        $results = array();
        while($row = mysqli_fetch_assoc($result)){
            $s = new Section($row['ID'], $row['name'], $row['visual'], $row['active'], $row['color'], $row['arrangement'], $row['parent']);
jlopez's avatar
jlopez committed
544
545
546
547
548
            array_push($results,$s);
        }
        return $results;
    }

jlopez's avatar
jlopez committed
549
550
551
552
553
    /**
     * Get all Section
     * 
     * @return array
     */
jlopez's avatar
jlopez committed
554
555
556
557
558
    public function getSection() {
        $sql = "SELECT * FROM `Section` ORDER BY `Section`.`arrangement` ASC;";
        $result = mysqli_query($this->dbh, $sql);
        $results = array();
        while($row = mysqli_fetch_assoc($result)){
jlopez's avatar
jlopez committed
559
            $s = new Section($row['ID'], $row['name'], $row['visual'], $row['active'], $row['color'], $row['arrangement'], $row['parent']);
jlopez's avatar
jlopez committed
560
            array_push($results,$s);
jlopez's avatar
jlopez committed
561
562
563
564
        }
        return $results;
    }

jlopez's avatar
jlopez committed
565
566
567
568
569
570
571
    /**
     * Get number packages For Distribution
     * 
     * @deprecated
     * 
     * @return int
     */
jlopez's avatar
jlopez committed
572
573
574
575
576
577
578
579
580
581
582
    public function getNumberPackage($name) {

        $sql = "SELECT COUNT(*) as number FROM `$name` WHERE 1 ";

        $result = mysqli_query($this->dbh, $sql);
        while($row = mysqli_fetch_assoc($result)){
            return $row['number'];
        }
        return 0;
    }

jlopez's avatar
jlopez committed
583
584
585
586
587
    /**
     * Get all packages
     * 
     * @deprecated
     */
jlopez's avatar
jlopez committed
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
    public function getPackages($distrib, $filter, $patternName, $patternDescription, $limit) {
        if($patternName and $patternDescription) {
            $sql = "SELECT * FROM `$distrib` WHERE `name` LIKE '%$filter%' or `description` LIKE '%$filter%' ORDER BY CASE  WHEN `name` LIKE '$filter' THEN 1 WHEN `name` LIKE '$filter%' THEN 2 WHEN `name` LIKE '%$filter' THEN 4 ELSE 3 END LIMIT $limit;";
        }
        elseif ($patternName) {
            $sql = " SELECT * FROM `$distrib` WHERE `name` LIKE '%$filter%' ORDER BY CASE  WHEN `name` LIKE '$filter' THEN 1 WHEN `name` LIKE '$filter%' THEN 2 WHEN `name` LIKE '%$filter' THEN 4 ELSE 3 END LIMIT $limit;";
        }
        elseif ($patternDescription) {
            $sql = "SELECT * FROM `$distrib` WHERE `description` LIKE '%$filter%' LIMIT $limit;";
        } else {
            return array();
        }

        $result = mysqli_query($this->dbh, $sql);
        $results = array();
        while($row = mysqli_fetch_assoc($result)){
jlopez's avatar
jlopez committed
604
            $package = new Package($row['name'], $row['version'], $row['description'], $row['doc'], $row['other']);
jlopez's avatar
jlopez committed
605
606
607
608
609
            array_push($results,$package);
        }
        return $results;
    }

jlopez's avatar
jlopez committed
610
611
612
613
614
615
    /**
     * Check if table exist in database
     * 
     * @param string $name The name of the table
     * 
     */
jlopez's avatar
jlopez committed
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
    public function checkTableExist($name) {
        $sql = "SELECT count(*) as number FROM information_schema.TABLES WHERE (TABLE_SCHEMA = 'wicopa') AND (TABLE_NAME = '$name')";
        
        $result = mysqli_query($this->dbh, $sql);
        if($result) {

            while($row = mysqli_fetch_assoc($result)){
                return $row['number'];
            }

        } else {
            var_dump(mysqli_error($this->dbh));
            die();
        }
    }

jlopez's avatar
jlopez committed
632
633
634
    /**
     * Create ofject in database
     */
jlopez's avatar
jlopez committed
635
636
637
638
639
640
641
642
643
644
645
646
647
    public function create($object) {

        $result = mysqli_query($this->dbh, $object->getInsert());

        if($result) {
            
        } else {
            var_dump(mysqli_error($this->dbh));
            die();
        }
    }


jlopez's avatar
jlopez committed
648
649
650
    /**
     * Update ofject in database
     */
jlopez's avatar
jlopez committed
651
    public function update($object) {
jlopez's avatar
Fix #7    
jlopez committed
652
        $result = mysqli_query($this->dbh, $object->getUpdate()); 
jlopez's avatar
jlopez committed
653
654
655
656
657
658
659
660
661
        if($result) {
            
        } else {
            var_dump(mysqli_error($this->dbh));
            die();
        }
    }


jlopez's avatar
jlopez committed
662
663
664
    /**
     * Delete ofject in database
     */
jlopez's avatar
jlopez committed
665
666
667
668
669
670
671
672
673
674
    public function delete($object) {
        $result = mysqli_query($this->dbh, $object->getDelete());
        if($result) {
            
        } else {
            var_dump(mysqli_error($this->dbh));
            die();
        }
    }

jlopez's avatar
jlopez committed
675
676
677
    /**
     * Check admin pass
     */
jlopez's avatar
jlopez committed
678
    public function verifyPass($username, $pass) {
jlopez's avatar
jlopez committed
679
        if($username == "admin" && Conf::dbEncodePass($pass)==Conf::$KK) {
jlopez's avatar
jlopez committed
680
681
            return 1;
        } else {
jlopez's avatar
jlopez committed
682
683
684
685
            # if you want guest admin
            //if($username == "guest" && $pass == "2019mbb") {
            //    return 2;
            //} else {
jlopez's avatar
jlopez committed
686
                return 0;
jlopez's avatar
jlopez committed
687
            //}
jlopez's avatar
jlopez committed
688
689
690
        }
    }

jlopez's avatar
jlopez committed
691
692
693
694
695
    /**
     * Get number docker container
     * 
     * @return int
     */
696
697
698
699
700
701
702
703
704
705
706
707
708
709
    public function getNumberDockerContainer() {
        $sql = 'SELECT count(*) as docker FROM `Container` WHERE type = "Docker" AND visibility = 1;';
        $result = mysqli_query($this->dbh, $sql);
        if($result) {

            while($row = mysqli_fetch_assoc($result)){
                return $row['docker'];
            }

        }

        return 0;
    }

jlopez's avatar
jlopez committed
710
711
712
713
714
    /**
     * Get number singularity container
     * 
     * @return int
     */
715
716
717
718
719
720
721
722
723
724
725
726
727
728
    public function getNumberSingularityContainer() {
        $sql = 'SELECT count(*) as singularity FROM `Container` WHERE type = "Singularity" AND visibility = 1';
        $result = mysqli_query($this->dbh, $sql);
        if($result) {

            while($row = mysqli_fetch_assoc($result)){
                return $row['singularity'];
            }

        }

        return 0;
    }

jlopez's avatar
jlopez committed
729

jlopez's avatar
jlopez committed
730
731


jlopez's avatar
jlopez committed
732
    //LOAD DATA LOCAL INFILE "/home/jimmy/jimmy/web/wicopa/packages/fedora:28/packages.csv" INTO TABLE fedora COLUMNS TERMINATED BY ';' OPTIONALLY ENCLOSED BY '"' ESCAPED BY '"' LINES TERMINATED BY '\n';
jlopez's avatar
jlopez committed
733
}