1<?php
2/*
3 * Copyright 2005-2016 OCSInventory-NG/OCSInventory-ocsreports contributors.
4 * See the Contributors file for more details about them.
5 *
6 * This file is part of OCSInventory-NG/OCSInventory-ocsreports.
7 *
8 * OCSInventory-NG/OCSInventory-ocsreports is free software: you can redistribute
9 * it and/or modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation, either version 2 of the License,
11 * or (at your option) any later version.
12 *
13 * OCSInventory-NG/OCSInventory-ocsreports is distributed in the hope that it
14 * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
15 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with OCSInventory-NG/OCSInventory-ocsreports. if not, write to the
20 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21 * MA 02110-1301, USA.
22 */
23require_once('require/function_admininfo.php');
24$table_name = $form_name;
25//search all admininfo for this computer
26$info_account_id = admininfo_snmp($systemid);
27
28
29if (isset($protectedPost['ADMIN']) && $protectedPost['ADMIN'] == 'ADMIN' && !isset($_SESSION['OCS']['ADMIN']['ACCOUNTINFO'])) {
30    $_SESSION['OCS']['ADMIN']['ACCOUNTINFO'] = true;
31} elseif (isset($protectedPost['ADMIN']) && $protectedPost['ADMIN'] == 'ADMIN' && isset($_SESSION['OCS']['ADMIN']['ACCOUNTINFO'])) {
32    unset($_SESSION['OCS']['ADMIN']['ACCOUNTINFO']);
33}
34
35if ($_SESSION['OCS']['profile']->getConfigValue('ACCOUNTINFO') == 'YES' && isset($_SESSION['OCS']['ADMIN']['ACCOUNTINFO'])) {
36    $admin_accountinfo = true;
37}
38
39$list_tab = find_all_account_tab('TAB_ACCOUNTSNMP', 'SNMP', 1);
40if ($list_tab != '') {
41    if ($protectedPost['Valid_modif'] != "") {
42        foreach ($protectedPost as $field => $value) {
43            $temp_field = explode('_', $field);
44            if (array_key_exists($temp_field[0] . '_' . $temp_field[1], $info_account_id) || $temp_field[0] == 'TAG') {
45                //cas of checkbox
46                if (isset($temp_field[2])) {
47                    $data_fields_account[$temp_field[0] . "_" . $temp_field[1]] .= $temp_field[2] . "&&&";
48                } else {
49                    $data_fields_account[$field] = $value;
50                }
51            }
52        }
53        updateinfo_snmp($systemid, $data_fields_account);
54        //search all admininfo for this computer
55        $info_account_id = admininfo_snmp($systemid);
56    }
57    unset($action_updown);
58    //UP/DOWN
59    if (is_defined($protectedPost['UP'])) {
60        $action_updown = 'UP';
61    }
62    if (is_defined($protectedPost['DOWN'])) {
63        $action_updown = 'DOWN';
64    }
65
66    if (isset($action_updown)) {
67        $new_order = find_new_order($action_updown, $protectedPost[$action_updown], 'SNMP', $protectedPost['onglet']);
68        if ($new_order) {
69            update_accountinfo_config($new_order['OLD'], array('SHOW_ORDER' => $new_order['NEW_VALUE']));
70            update_accountinfo_config($new_order['NEW'], array('SHOW_ORDER' => $new_order['OLD_VALUE']));
71        }
72    }
73
74    //print_r($info_account_id);
75    if (!is_defined($protectedPost['onglet']) || !is_numeric($protectedPost['onglet'])) {
76        $protectedPost['onglet'] = $list_tab['FIRST'];
77    }
78    unset($list_tab['FIRST']);
79
80    echo "<br>";
81    echo open_form($form_name);
82    onglet($list_tab, $form_name, "onglet", 6);
83    echo '<div class="col-md-12" >';
84    if ($_SESSION['OCS']['profile']->getConfigValue('ACCOUNTINFO') == 'YES') {
85        $show_admin_button = "<a href=# OnClick='pag(\"ADMIN\",\"ADMIN\",\"" . $form_name . "\");'>";
86        if (isset($_SESSION['OCS']['ADMIN']['ACCOUNTINFO'])) {
87            $show_admin_button .= "<img src='image/success.png'></a>";
88        } else {
89            $show_admin_button .= "<span class='glyphicon glyphicon-edit'></span></a>";
90        }
91    } else {
92        $show_admin_button = '';
93    }
94    $sql_admin_info = "select ID,TYPE,NAME,COMMENT,NAME_ACCOUNTINFO,SHOW_ORDER from accountinfo_config where ID_TAB = %s and account_type='SNMP'
95						order by SHOW_ORDER ASC";
96    $arg_admin_info = array($protectedPost['onglet']);
97    $res_admin_info = mysql2_query_secure($sql_admin_info, $_SESSION['OCS']["readServer"], $arg_admin_info);
98    $num_row = mysqli_num_rows($res_admin_info);
99    $name_field = array();
100    $tab_name = array();
101    $type_field = array();
102    $value_field = array();
103    $config['COMMENT_AFTER'] = array();
104    $config['SELECT_DEFAULT'] = array();
105    $config['JAVASCRIPT'] = array();
106    $config['SIZE'] = array();
107    $config['DDE'] = array();
108
109    $nb_row = 1;
110    while ($val_admin_info = mysqli_fetch_array($res_admin_info)) {
111        array_push($config['DDE'], $systemid);
112        //if name_accountinfo is not null
113        //column name in accountinfo table is name_accountinfo
114        //functionality for compatibility with older version of OCS
115        //we can't change the name TAG in accountinfo table
116        if ($val_admin_info['NAME_ACCOUNTINFO'] != '') {
117            $name_accountinfo = trim($val_admin_info['NAME_ACCOUNTINFO']);
118        } else {
119            $name_accountinfo = 'fields_' . $val_admin_info['ID'];
120        }
121
122        $up_png = "";
123
124        if ($nb_row != 1) {
125            $up_png .= updown($val_admin_info['ID'], 'UP');
126        }
127
128        if ($nb_row != $num_row) {
129            $up_png .= updown($val_admin_info['ID'], 'DOWN');
130        }
131        if ($val_admin_info['TYPE'] == 2
132                or $val_admin_info['TYPE'] == 4
133                or $val_admin_info['TYPE'] == 7) {
134            array_push($config['JAVASCRIPT'], '');
135            array_push($config['SIZE'], '');
136            if ($admin_accountinfo) {
137                array_push($config['COMMENT_AFTER'], $up_png . "<a href=\"index.php?" . PAG_INDEX . "=" . $pages_refs['ms_adminvalues'] . "&head=1&tag=ACCOUNT_SNMP_VALUE_" . $val_admin_info['NAME'] . "\"><img src=image/plus.png></a>");
138            } else {
139                array_push($config['COMMENT_AFTER'], '');
140            }
141            array_push($config['SELECT_DEFAULT'], 'YES');
142            $field_select_values = find_value_field("ACCOUNT_SNMP_VALUE_" . $val_admin_info['NAME']);
143            array_push($value_field, $field_select_values);
144            //cas of checkbox
145            if ($val_admin_info['TYPE'] == 4) {
146                $temp_val = explode('&&&', $info_account_id[$name_accountinfo]);
147                $i = 0;
148                while (isset($temp_val[$i])) {
149                    $protectedPost[$name_accountinfo . '_' . $temp_val[$i]] = 'on';
150                    $i++;
151                }
152            } else {
153                $protectedPost[$name_accountinfo] = $info_account_id[$name_accountinfo];
154            }
155        } elseif ($val_admin_info['TYPE'] == 6) {
156            array_push($value_field, $info_account_id[$name_accountinfo]);
157            if ($admin_accountinfo) {
158                array_push($config['COMMENT_AFTER'], $up_png . datePick($name_accountinfo));
159            } else {
160                array_push($config['COMMENT_AFTER'], datePick($name_accountinfo));
161            }
162            array_push($config['JAVASCRIPT'], "READONLY");
163            array_push($config['SELECT_DEFAULT'], '');
164            array_push($config['SIZE'], '8');
165        } elseif ($val_admin_info['TYPE'] == 5) {
166            array_push($value_field, "accountinfo");
167            if ($admin_accountinfo) {
168                array_push($config['COMMENT_AFTER'], $up_png);
169            } else {
170                array_push($config['COMMENT_AFTER'], "");
171            }
172            array_push($config['SELECT_DEFAULT'], '');
173            array_push($config['JAVASCRIPT'], '');
174            array_push($config['SIZE'], '');
175        } else {
176            array_push($value_field, $info_account_id[$name_accountinfo]);
177            if ($admin_accountinfo) {
178                array_push($config['COMMENT_AFTER'], $up_png);
179            } else {
180                array_push($config['COMMENT_AFTER'], "");
181            }
182            array_push($config['SELECT_DEFAULT'], '');
183            array_push($config['JAVASCRIPT'], '');
184            array_push($config['SIZE'], '');
185        }
186
187        array_push($name_field, $name_accountinfo);
188        array_push($tab_name, $val_admin_info['COMMENT']);
189        if ($_SESSION['OCS']['profile']->getConfigValue('CHANGE_ACCOUNTINFO') == "YES") {
190            array_push($type_field, $val_admin_info['TYPE']);
191        } else {
192            array_push($type_field, 3);
193        }
194
195        $nb_row++;
196    }
197
198    $tab_typ_champ = show_field($name_field, $type_field, $value_field, $config);
199    if ($_SESSION['OCS']['profile']->getConfigValue('ACCOUNTINFO') == 'YES') {
200        $tab_hidden = array('ADMIN' => '', 'UP' => '', 'DOWN' => '');
201    }
202
203    modif_values($tab_name, $tab_typ_champ, $tab_hidden, array(
204        'form_name' => 'NO_FORM',
205        'top_action' => $show_admin_button
206    ));
207
208    echo "</div>";
209    echo close_form();
210}
211?>
212