File: function_dico.php

package info (click to toggle)
ocsinventory-server 2.5%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 7,088 kB
  • sloc: php: 27,462; perl: 8,241; sh: 1,680; sql: 1,355; xml: 1,041; makefile: 34
file content (109 lines) | stat: -rw-r--r-- 4,544 bytes parent folder | download
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
<?php
/*
 * Copyright 2005-2016 OCSInventory-NG/OCSInventory-ocsreports contributors.
 * See the Contributors file for more details about them.
 *
 * This file is part of OCSInventory-NG/OCSInventory-ocsreports.
 *
 * OCSInventory-NG/OCSInventory-ocsreports is free software: you can redistribute
 * it and/or modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation, either version 2 of the License,
 * or (at your option) any later version.
 *
 * OCSInventory-NG/OCSInventory-ocsreports is distributed in the hope that it
 * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with OCSInventory-NG/OCSInventory-ocsreports. if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301, USA.
 */

function search_all_item() {
    $result_search_soft = mysqli_query($_SESSION['OCS']["readServer"], $_SESSION['OCS']['query_dico']);
    while ($item_search_soft = mysqli_fetch_object($result_search_soft)) {
        $list[] = $item_search_soft->ID;
    }
    return $list;
}

function del_soft($onglet, $list_soft) {
    if ($_SESSION['OCS']['usecache']) {
        $table = "softwares_name_cache";
    } else {
        $table = "softwares";
    }

    $sql_soft_name = "select distinct NAME from " . $table . " where ID in (" . implode(",", $list_soft) . ")";
    $result_soft_name = mysqli_query($_SESSION['OCS']["readServer"], $sql_soft_name);
    while ($item_soft_name = mysqli_fetch_object($result_soft_name)) {
        $list_soft_name[] = str_replace('"', '\"', $item_soft_name->NAME);
    }
    if ($onglet == "CAT" || $onglet == "UNCHANGED") {
        $sql_delete = "delete from dico_soft where extracted in (\"" . implode("\",\"", $list_soft_name) . "\")";
    }
    if ($onglet == "IGNORED") {
        $sql_delete = "delete from dico_ignored where extracted in (\"" . implode("\",\"", $list_soft_name) . "\")";
    }
    mysqli_query($_SESSION['OCS']["writeServer"], $sql_delete);
}

function trans($onglet, $list_soft, $affect_type, $new_cat, $exist_cat) {
    global $l;
    
    // If new cat and exist cat are empty return
    if($new_cat == '' and $exist_cat == ''){
        return ;
    }
    
    if ($_SESSION['OCS']['usecache']) {
        $table = "softwares_name_cache";
    } else {
        $table = "softwares";
    }
    
    //verif is this cat exist
    if ($new_cat != '') {
        $sql_verif = "select extracted from dico_soft where formatted ='" . mysqli_real_escape_string($_SESSION['OCS']["readServer"], $new_cat) . "'";
        $result_search_soft = mysqli_query($_SESSION['OCS']["readServer"], $sql_verif);
        $item_search_soft = mysqli_fetch_object($result_search_soft);
        if (isset($item_search_soft->extracted) || $new_cat == "IGNORED" || $new_cat == "UNCHANGED") {
            $already_exist = true;
        }
    }

    if ($onglet == "NEW") {
        $table = "softwares";
        $ok = true;
    } else {
        if (!isset($already_exist)) {
            del_soft($onglet, $list_soft);
        }
        $ok = true;
    }

    if ($ok == true) {
        if ($affect_type == "EXIST_CAT") {
            if ($exist_cat == "IGNORED") {
                $sql = "insert dico_ignored (extracted) select distinct NAME from " . $table . " where ID in (" . implode(",", $list_soft) . ")";
            } elseif ($exist_cat == "UNCHANGED") {
                $sql = "insert dico_soft (extracted,formatted) select distinct NAME,NAME from " . $table . " where ID in (" . implode(",", $list_soft) . ")";
            } else {
                $sql = "insert dico_soft (extracted,formatted) select distinct NAME,'" . mysqli_real_escape_string($_SESSION['OCS']["readServer"], $exist_cat) . "' from " . $table . " where ID in (" . implode(",", $list_soft) . ")";
            }
        } else {
            if (!isset($already_exist)) {
                $sql = "insert dico_soft (extracted,formatted) select distinct NAME,'" . mysqli_real_escape_string($_SESSION['OCS']["readServer"], $new_cat) . "' from " . $table . " where ID in (" . implode(",", $list_soft) . ")";
            } else {
                echo "<script>alert('" . $l->g(771) . "')</script>";
            }
        }
        if ($sql != '') {
            mysqli_query($_SESSION['OCS']["writeServer"], $sql);
        }
    }
}

?>