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 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
|
<?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.
*/
if (AJAX) {
parse_str($protectedPost['ocs']['0'], $params);
$protectedPost += $params;
ob_start();
}
/*
* Page des groupes
*/
require_once('require/function_groups.php');
require_once('require/function_computers.php');
//ADD new static group
if ($protectedPost['Valid_modif']) {
$result = creat_group($protectedPost['NAME'], $protectedPost['DESCR'], '', '', 'STATIC');
if ($result['RESULT'] == "ERROR") {
msg_error($result['LBL']);
} elseif ($result['RESULT'] == "OK") {
msg_success($result['LBL']);
unset($protectedPost['add_static_group']);
}
$tab_options['CACHE'] = 'RESET';
}
//reset add static group
if ($protectedPost['Reset_modif'] || ($protectedPost['onglet'] != $protectedPost['old_onglet'])) {
unset($protectedPost['add_static_group']);
}
$tab_options = $protectedPost;
//view only your computers
if ($_SESSION['OCS']['profile']->getRestriction('GUI') == 'YES') {
$mycomputers = computer_list_by_tag();
if ($mycomputers == "ERROR") {
msg_error($l->g(893));
require_once(FOOTER_HTML);
die();
}
}
//View for all profils?
if (!AJAX) {
if (is_defined($protectedPost['CONFIRM_CHECK'])) {
$result = group_4_all($protectedPost['CONFIRM_CHECK']);
}
}
//if delete group
if ($protectedPost['SUP_PROF'] != "") {
$result = delete_group($protectedPost['SUP_PROF']);
if ($result['RESULT'] == "ERROR") {
msg_error($result['LBL']);
}
$tab_options['CACHE'] = 'RESET';
}
$form_name = 'groups';
$tab_options['form_name'] = $form_name;
echo open_form($form_name, '', '', 'form-horizontal');
//view all groups
if ($_SESSION['OCS']['profile']->getConfigValue('GROUPS')=="YES"){
$def_onglets['DYNA']=$l->g(810); //Dynamic group
$def_onglets['STAT']=$l->g(809); //Static group centraux
if ($_SESSION['OCS']["use_redistribution"] == 1)
$def_onglets['SERV']=mb_strtoupper($l->g(651));
if ($protectedPost['onglet'] == "")
$protectedPost['onglet']="STAT";
//show onglet
show_tabs($def_onglets,$form_name,"onglet",true);
echo '<div class="col col-md-10">';
}else{
$protectedPost['onglet']="STAT";
}
$list_fields = array('GROUP_NAME' => 'h.NAME',
'GROUP_ID' => 'h.ID',
'DESCRIPTION' => 'h.DESCRIPTION',
'CREATE' => 'h.LASTDATE',
'NBRE' => 'NBRE');
//only for admins
if ($_SESSION['OCS']['profile']->getConfigValue('GROUPS') == "YES") {
if ($protectedPost['onglet'] == "STAT") {
$list_fields['CHECK'] = 'ID';
}
$list_fields['SUP'] = 'ID';
$tab_options['LBL_POPUP']['SUP'] = 'NAME';
$tab_options['LBL']['SUP'] = $l->g(122);
}
//changement de nom à l'affichage des champs
$tab_options['LBL']['CHECK'] = $l->g(52);
$tab_options['LBL']['GROUP_NAME'] = $l->g(49);
$table_name = "LIST_GROUPS";
$tab_options['table_name'] = $table_name;
$default_fields = array('GROUP_NAME' => 'GROUP_NAME', 'DESCRIPTION' => 'DESCRIPTION', 'CREATE' => 'CREATE', 'NBRE' => 'NBRE', 'SUP' => 'SUP', 'CHECK' => 'CHECK');
$list_col_cant_del = array('GROUP_NAME' => 'GROUP_NAME', 'SUP' => 'SUP', 'CHECK' => 'CHECK');
$query = prepare_sql_tab($list_fields, array('SUP', 'CHECK', 'NBRE'));
$tab_options['ARG_SQL'] = $query['ARG'];
$querygroup = $query['SQL'];
//requete pour les groupes de serveurs
if ($protectedPost['onglet'] == "SERV") {
$querygroup .= " from hardware h,download_servers ds where ds.group_id=h.id and h.deviceid = '_DOWNLOADGROUP_'";
//calcul du nombre de machines par groupe de serveur
$sql_nb_mach = "SELECT count(*) nb, group_id
from download_servers group by group_id";
} else { //requete pour les groupes 'normaux'
$querygroup .= " from hardware h,groups g ";
$querygroup .= "where g.hardware_id=h.id and h.deviceid = '_SYSTEMGROUP_' ";
if ($protectedPost['onglet'] == "DYNA") {
$querygroup .= " and ((g.request is not null and trim(g.request) != '')
or (g.xmldef is not null and trim(g.xmldef) != ''))";
} elseif ($protectedPost['onglet'] == "STAT") {
$querygroup .= " and (g.request is null or trim(g.request) = '')
and (g.xmldef is null or trim(g.xmldef) = '') ";
}
if ($_SESSION['OCS']['profile']->getConfigValue('GROUPS') != "YES") {
$querygroup .= " and h.workgroup='GROUP_4_ALL' ";
}
//calcul du nombre de machines par groupe
$sql_nb_mach = "SELECT count(*) nb, group_id
from groups_cache gc,hardware h where h.id=gc.hardware_id ";
if ($_SESSION['OCS']['profile']->getRestriction('GUI') == "YES") {
$sql_nb_mach .= " and gc.hardware_id in " . $mycomputers;
}
$sql_nb_mach .= " group by group_id";
}
$querygroup .= " group by h.ID";
$result = mysql2_query_secure($sql_nb_mach, $_SESSION['OCS']["readServer"]);
while ($item = mysqli_fetch_object($result)) {
//on force les valeurs du champ "nombre" à l'affichage
$tab_options['VALUE']['NBRE'][$item->group_id] = $item->nb;
$_SESSION['OCS']['VALUE_FIXED'][$tab_options['table_name']]['NBRE'][$item->group_id] = $item->nb;
}
//Modif ajoutée pour la prise en compte
//du chiffre à rajouter dans la colonne de calcul
//quand on a un seul groupe et qu'aucune machine n'est dedant.
if (!isset($tab_options['VALUE']['NBRE'])) {
$tab_options['VALUE']['NBRE'][] = 0;
}
//on recherche les groupes visible pour cocher la checkbox à l'affichage
if ($protectedPost['onglet'] == "STAT") {
$sql = "select id from hardware where workgroup='GROUP_4_ALL'";
$result = mysql2_query_secure($sql, $_SESSION['OCS']["readServer"]);
while ($item = mysqli_fetch_object($result)) {
$protectedPost['check' . $item->id] = "check";
}
}
//on ajoute un javascript lorsque l'on clic sur la visibilité du groupe pour tous
$tab_options['JAVA']['CHECK']['NAME'] = "NAME";
$tab_options['JAVA']['CHECK']['QUESTION'] = $l->g(811);
$tab_options['FILTRE'] = array('NAME' => $l->g(679), 'DESCRIPTION' => $l->g(53));
//affichage du tableau
$result_exist = ajaxtab_entete_fixe($list_fields, $default_fields, $tab_options, $list_col_cant_del);
//if your profil is an admin groups, you can create one
if ($_SESSION['OCS']['profile']->getConfigValue('GROUPS') == "YES") {
if ($protectedPost['onglet'] == "STAT") {
?>
<div class="row">
<div class='col-md-12'>
<input type='submit' class='btn' name='add_static_group' value='<?php echo $l->g(587) ?>'>
</div>
</div>
<?php
}
}
//if user want add a new group
if (isset($protectedPost['add_static_group']) && $_SESSION['OCS']['profile']->getConfigValue('GROUPS') == "YES") {
?>
<div class="row rowMarginTop30">
<div class="col-md-12">
<?php
formGroup('text', 'NAME', $l->g(577), '20', '', $protectedPost['NAME']);
formGroup('text', 'DESCR', $l->g(53), '', '', $protectedPost['DESCR']);
?>
</div>
</div>
<div class="row">
<div class="col-md-12">
<input type="submit" name="Valid_modif" value="<?php echo $l->g(1363) ?>" class="btn btn-success">
<input type="submit" name="Reset_modif" value="<?php echo $l->g(1364) ?>" class="btn btn-danger">
</div>
</div>
<?php
}
echo '</div>';
//fermeture du formulaire
echo close_form();
if (AJAX) {
ob_end_clean();
tab_req($list_fields, $default_fields, $list_col_cant_del, $querygroup, $tab_options);
}
?>
|