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 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
|
<?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.
*/
class Stats{
public $form_name = "stats";
//We also initiate a counter variable to help us cyclically rotate through
//the array of colors.
public $FC_ColorCounter = 0;
public $arr_FCColors = [0 => "1941A5",
1 => "AFD8F8",
2 => "F6BD0F",
3 => "8BBA00",
4 => "A66EDD",
5 => "F984A1",
6 => "CCCC00",//Chrome Yellow+Green
7 => "999999", //Grey
8 => "0099CC", //Blue Shade
9 => "FF0000", //Bright Red
10 => "006F00", //Dark Green
11 => "0099FF", //Blue (Light)
12 => "FF66CC", //Dark Pink
13 => "669966", //Dirty green
14 => "7C7CB4", //Violet shade of blue
15 => "FF9933", //Orange
16 => "9900FF", //Violet
17 => "99FFCC", //Blue+Green Light
18 => "CCCCFF", //Light violet
19 => "669900",
];
//Shade of green
//getFCColor method helps return a color from arr_FCColors array. It uses
//cyclic iteration to return a color from a given index. The index value is
//maintained in FC_ColorCounter
public function showForm($form){
global $l;
global $protectedPost;
foreach($form as $key => $value){
if ($key == 'NB_OS') {
$sql = "select count(h.osname) c,h.osname as name from hardware h LEFT JOIN accountinfo a ON a.HARDWARE_ID = h.ID where h.osname != '' AND h.deviceid != '_SYSTEMGROUP_'";
if (is_defined($_SESSION['OCS']["mesmachines"])) {
$sql .= " AND " . $_SESSION['OCS']["mesmachines"];
}
$sql .= " group by h.osname order by count(h.osname) DESC ";
$height_legend = 300;
} else {
$sql = "select count(h.useragent) c,h.useragent as name from hardware h LEFT JOIN accountinfo a ON a.HARDWARE_ID = h.ID where h.useragent != '' AND h.deviceid != '_SYSTEMGROUP_'";
if (is_defined($_SESSION['OCS']["mesmachines"])) {
$sql .= " AND " . $_SESSION['OCS']["mesmachines"];
}
$sql .= " group by h.useragent order by count(h.useragent) DESC ";
$height_legend = 300;
}
$res = mysql2_query_secure($sql, $_SESSION['OCS']["readServer"]);
$i = 0;
while ($row = mysqli_fetch_object($res)) {
if($i <= 10){
$chart[$key]['count'][$i] = $row->c;
$chart[$key]['name_value'][$i] = addslashes($row->name);
$chart[$key]['name'] = [$key];
if($key == 'NB_OS'){
$chart[$key]['title'] = $l->g(783);
}else{
$chart[$key]['title'] = $l->g(784);
}
}
$i++;
}
if($key == 'SEEN'){
//last seen since
$date = date("y-m-d",strtotime("-15 day"));
$sql_seen = "SELECT DATE_FORMAT(h.lastcome, '%Y-%m') AS contact, count(h.lastcome) AS conta FROM `hardware` h LEFT JOIN accountinfo a ON a.HARDWARE_ID = h.ID WHERE h.LASTCOME < '".$date."' AND h.deviceid != '_SYSTEMGROUP_'";
if (is_defined($_SESSION['OCS']["mesmachines"])) {
$sql_seen .= " AND " . $_SESSION['OCS']["mesmachines"];
}
$sql_seen .= " GROUP BY contact ORDER BY contact ASC";
$result_seen = mysql2_query_secure($sql_seen, $_SESSION['OCS']["readServer"]);
$seen = array();
$seen_name = array();
$seen_quant = array();
while($item = mysqli_fetch_array($result_seen)){
$seen_name[] = $item['contact'];
$seen_quant[] = $item['conta'];
}
$seen = "['".implode("','",$seen_name)."']";
$quants_seen = "['".implode("','",$seen_quant)."']";
$chart[$key]['title'] = $l->g(820).' > 15 '.$l->g(496);
}
if($key == 'MANUFAC'){
$sql_man = "SELECT b.SMANUFACTURER AS man, count(b.SMANUFACTURER) AS c_man FROM `bios` b LEFT JOIN accountinfo a ON a.HARDWARE_ID = b.HARDWARE_ID";
if (is_defined($_SESSION['OCS']["mesmachines"])) {
$sql_man .= " WHERE " . $_SESSION['OCS']["mesmachines"];
}
$sql_man .= " group by b.SMANUFACTURER ORDER BY count(b.SMANUFACTURER) DESC LIMIT 10";
$result_man = mysql2_query_secure($sql_man, $_SESSION['OCS']["readServer"]);
$man = array();
$man_name = array();
$man_quant = array();
while($item = mysqli_fetch_array($result_man)){
$man_name[] = $item['man'];
$man_quant[] = $item['c_man'];
}
$man = "['".implode("','",$man_name)."']";
$quants_man = "['".implode("','",$man_quant)."']";
$chart[$key]['title'] = $l->g(851).' - Top 10';
}
if($key == 'TYPE'){
$sql_type = "SELECT CASE WHEN TRIM(b.type) ='' THEN 'Unknow' ELSE b.type END as type, count(b.type) AS conta FROM `bios` b LEFT JOIN accountinfo a ON a.HARDWARE_ID = b.HARDWARE_ID";
if (is_defined($_SESSION['OCS']["mesmachines"])) {
$sql_type .= " WHERE " . $_SESSION['OCS']["mesmachines"];
}
$sql_type .= " GROUP BY type";
$result_type = mysql2_query_secure($sql_type, $_SESSION['OCS']["readServer"]);
$type = array();
$type_name = array();
$type_quant = array();
while($item = mysqli_fetch_array($result_type)){
$type_name[] = $item['type'];
$type_quant[] = $item['conta'];
}
$type = "['".implode("','",$type_name)."']";
$quants_type = "['".implode("','",$type_quant)."']";
$chart[$key]['title'] = $l->g(854);
}
}
if (isset($chart)) {
$stats = new StatsChartsRenderer;
$stats->createChartCanvas($form);
$stats->createChart($chart, $seen, $quants_seen, $man, $quants_man, $type, $quants_type);
return true;
} else {
return false;
}
}
public function showForm2($form){
global $l;
global $protectedPost;
//last seen since
$date = date("y-m-d",strtotime("-15 day"));
$sql_seen = "SELECT DATE_FORMAT(lastcome, '%Y-%m') AS contact, count(lastcome) AS conta
FROM `hardware`
WHERE LASTCOME < '".$date."'
group by contact
ORDER BY `contact` ASC";
$result_seen = mysql2_query_secure($sql_seen, $_SESSION['OCS']["readServer"]);
$seen = array();
$seen_name = array();
$seen_quant = array();
while($item = mysqli_fetch_array($result_seen)){
$seen_name[] = $item['contact'];
$seen_quant[] = $item['conta'];
}
$seen = "['".implode("','",$seen_name)."']";
$quants_seen = "['".implode("','",$seen_quant)."']";
if (!empty($seen)) {
$stats = new StatsChartsRenderer;
$stats->createChartCanvas2($form);
$stats->createLineChart($seen, $quants_seen);
return true;
} else {
return false;
}
}
public function find_ivalues($packid) {
$sql = "SELECT id FROM download_enable WHERE fileid='%s'";
$arg = $packid;
$res = mysql2_query_secure($sql, $_SESSION['OCS']["readServer"], $arg);
while ($row = mysqli_fetch_array($res)) {
$result[] = $row['id'];
}
return $result;
}
public function find_device_line($status, $packid) {
//get all ivalues
$ivalues = $this->find_ivalues($packid);
//get hardwareid foreach ivalue
foreach ($ivalues as $value) {
$sql = "select hardware_id,ivalue from devices where name='DOWNLOAD' and tvalue";
if ($status == "NULL") {
$sql .= " IS NULL ";
$arg = $value;
} elseif ($status == "NOTNULL") {
$sql .= " IS NOT NULL ";
$arg = $value;
} else {
$sql .= " LIKE '%s' ";
$arg = array($status, $value);
}
$sql .= "AND ivalue='%s' " .
"AND hardware_id NOT IN (SELECT id FROM hardware WHERE deviceid='_SYSTEMGROUP_')";
$res = mysql2_query_secure($sql, $_SESSION['OCS']["readServer"], $arg);
while ($row = mysqli_fetch_object($res)) {
$result[$value][] = $row->hardware_id;
}
}
return $result;
}
}
|