//====================================================================================
// OCS INVENTORY REPORTS
// Copyleft Pierre LEMMET 2005
// Web: http://ocsinventory.sourceforge.net
//
// This code is open source and may be copied and modified as long as the source
// code is always made freely available.
// Please refer to the General Public Licence http://www.gnu.org/ or Licence.txt
//====================================================================================
//Modified on 9/27/2005
$pgSize = $_SESSION["pcparpage"];
$rg = isset($_GET["rg"])?$_GET["rg"]:0;
set_time_limit(0);
/*
foreach($_POST as $key=>$val) {
if( ($fin = stristr ($key, "inputncat_")) && $val != "") {
$valName = substr( fromName(stripslashes($fin)), strlen("inputncat_"));
addSoft( $val, $valName);
}}
*/
$_GET["cat"] = isset($_GET["cat"]) ? $_GET["cat"] : (isset($_POST["alleracat"]) ? $_POST["alleracat"] : null ) ;
if( isset($_GET["cat"]) ) {
if( isset($_GET["search"]) && $_GET["search"] != "" ) {
$condG = " name LIKE '%".$_GET["search"]."%' AND";
$condO = " extracted LIKE '%".$_GET["search"]."%' AND";
}
$order = isset($_GET["order"])&&$_GET["order"]!="" ? $_GET["order"] : 1 ;
$laCat = stripslashes(fromName($_GET["cat"]));
if($laCat == "NEW")
$sens = $order != 1 ? "ASC" : "DESC";
else
$sens = "ASC";
if($laCat == "NEW") {
if(! isset($_GET["order"])) $sens = "DESC";
$reqLog = "SELECT COUNT(hardware_id) as 'nbdef',name as 'extracted' FROM softwares WHERE{$condG} name NOT IN
(SELECT DISTINCT(extracted) FROM dico_soft) AND name NOT IN
(SELECT DISTINCT(extracted) FROM dico_ignored) GROUP BY name ORDER BY $order $sens";
$reqCount = "SELECT COUNT(DISTINCT(name)) as 'nb' FROM softwares WHERE{$condG} name NOT IN
(SELECT DISTINCT(extracted) FROM dico_soft) AND name NOT IN
(SELECT DISTINCT(extracted) FROM dico_ignored)";
}
else if($laCat == "IGNORED") {
$reqLog = "SELECT s.extracted FROM dico_ignored s WHERE{$condO} 1=1 ORDER BY $order $sens ";
$reqCount = "SELECT COUNT(s.extracted) as 'nb' FROM dico_ignored s WHERE{$condO} 1=1";
}
else if($laCat == "UNCHANGED") {
$reqLog = "SELECT s.extracted FROM dico_soft s WHERE{$condO} extracted=formatted ORDER BY $order $sens";
$reqCount = "SELECT COUNT(s.extracted) as 'nb' FROM dico_soft s WHERE{$condO} extracted=formatted";
}
else {
$reqLog = "SELECT s.extracted FROM dico_soft s WHERE{$condO} s.formatted='$laCat' ORDER BY $order $sens";
$reqCount = "SELECT COUNT(s.extracted) as 'nb' FROM dico_soft s WHERE{$condO} s.formatted='$laCat'";
}
//echo $reqLog;
}
else if( isset($_GET["all"]) && $_GET["search"]!="" ) {
$reqLog = "SELECT distinct(name) as 'extracted' FROM softwares WHERE name LIKE '%".$_GET["search"]."%' order by name asc";
$reqCount = "SELECT count( distinct name) as 'nb' FROM softwares WHERE name LIKE '%".$_GET["search"]."%' order by name asc";
}
$lastCat = "";
if( isset($_POST["combocat"]) ) {
if(isset($_POST["all"])) {
$resAll = mysql_query($reqLog, $_SESSION["readServer"]) or die(mysql_error($_SESSION["readServer"]));
while($valAll = mysql_fetch_array($resAll)) {
$_POST[ urlencode($valAll["extracted"]) ] = "on";
}
unset($_POST["all"]);
}
foreach($_POST as $key=>$val) {
if($val == "on") {
$key = addslashes(fromName($key));
if( isset($_POST["inputcat"]) && $_POST["inputcat"] != "" ) {
addSoft( fromName($_POST["inputcat"]), $key);
$lastCat = fromName($_POST["inputcat"]);
}
else {
addSoft( fromName($_POST["combocat"]), $key);
$lastCat = fromName($_POST["combocat"]);
}
}
}
}
if( isset($reqLog) ) {
$reqLog .= " LIMIT $rg,$pgSize";
}
if( isset($_GET["delcat"]) ) {
delCat( fromName($_GET["delcat"]) );
}
?>
//les GET globaux a rajouter
$hiddens ="";
foreach ($_GET as $gk=>$gv) {
if( $gk=="rev"|| $gk=="suppCol" || $gk == "logout" || $gk=="newcol" || $gk=="order") continue;
if( $gk =="page" && ($gv==-1 || $gv==-2)) {
$gv = $_SESSION["pageCur"];
}
$hiddens .= "\n";
}
$machNmb = array(5,10,15,20,50,100);
$pcParPageHtml = "
";
if( isset($_GET["cat"]) ) {
$link = "multi=14&cat=".urlencode($_GET["cat"])."&search=".urlencode($_GET["search"]);
$resCount = mysql_query($reqCount, $_SESSION["readServer"]) or die(mysql_error($_SESSION["readServer"]));
$valCount = mysql_fetch_array($resCount);
$printNbr = $valCount["nb"] == 0 ? "VIDE" : $valCount["nb"];
printEnTete("Catégorie $laCat ( $printNbr )");
echo "
$pcParPageHtml <= ".$l->g(398)."
";
if( $valCount["nb"] > 0 ) {
$resLog = mysql_query($reqLog, $_SESSION["readServer"]) or die(mysql_error($_SESSION["readServer"]));
echo "";
}
echo "
";
}
else {
if( isset($_GET["oldv"]) ) {
$_GET["search"] = $_SESSION["search"] ;
$_GET["all"] = $_SESSION["all"] ;
$rg = isset($_SESSION["rg"])?$_SESSION["rg"]:0 ;
}
else {
$_SESSION["search"] = $_GET["search"] ;
$_SESSION["all"] = $_GET["all"] ;
$_SESSION["rg"] = $rg ;
}
$link = "multi=14&search=".urlencode($_GET["search"])."&order=$order";
// multi category search
if( isset($_GET["all"]) && $_GET["search"]!="" ) {
$link .= "&all=1";
echo "
";
}
}
else {
printEnTete($l->g(390));
if( isset($_GET["search"]) && $_GET["search"] != "" ) {
$cond = "AND formatted LIKE '%".$_GET["search"]."%'";
}
$reqCat = "SELECT formatted as 'name', COUNT(extracted) AS nbSoft FROM dico_soft WHERE extracted<>formatted $cond
GROUP BY formatted ORDER BY formatted ASC LIMIT $rg,$pgSize";
echo "
$pcParPageHtml";
//echo $reqCat;
$resCat = mysql_query($reqCat, $_SESSION["readServer"]) or die(mysql_error($_SESSION["readServer"]));
echo "";
echo "
";
echo "".$l->g(391)." | ".$l->g(381)." | ".$l->g(392)." |
";
$ligne = 0;
$reqNew = "SELECT COUNT(DISTINCT(name)) as nbNew FROM softwares WHERE name NOT IN (SELECT DISTINCT(extracted) FROM dico_soft)";
while($cat = mysql_fetch_array($resCat)) {
$laLigne = array("".$cat["name"]."", $cat["nbSoft"] );
$laLigne = array_merge($laLigne, array(""));
printLigne($laLigne, ($ligne%2 == 1 ? "#FFFFFF" : "#F2F2F2"));
$ligne++;
}
echo "
";
}
echo "
";
}
if( isset( $_SESSION["toBeMod"] ) ) {
//var_dump( $_SESSION["toBeMod"]);
computeChecksums();
unset( $_SESSION["toBeMod"] );
}
/*function allerA() {
return "";
}*/
function comboCat( $saufCat="", $lastCat="",$name='combocat' ) {
$reqCom = "SELECT formatted as 'name', COUNT(extracted) AS nbSoft FROM dico_soft WHERE extracted<>formatted AND formatted<>'$saufCat'
GROUP BY formatted ORDER BY formatted ASC";
//echo $reqCom;
$resCom = mysql_query($reqCom, $_SESSION["readServer"]) or die(mysql_error($_SESSION["readServer"]));
$ret = "";
return $ret;
}
function printLigne($ligne, $bgcol=false) {
if( $bgcol )
$affBg = "bgcolor='$bgcol'";
echo "";
foreach($ligne as $l) {
echo "$l | ";
}
echo "
";
}
function toName($nm) {
$ret = str_replace(".","%point%",$nm);
$ret = "checkbox_".$ret;
return urlencode($ret);
}
function fromName($nm) {
$ret = urldecode($nm);
$ret = str_replace("checkbox_","",$ret);
return str_replace("%point%",".",$ret);
}
function addSoft( $cat, $def) {
if( $cat == "UNCHANGED") {
$cat = $def;
}
if($cat == "IGNORED") {
delSoft($def);
$reqIgn = "INSERT INTO dico_ignored VALUES('$def')";
@mysql_query($reqIgn, $_SESSION["writeServer"]);
}
else {
delIgnored($def);
$reqUpd = "UPDATE dico_soft SET formatted='$cat' WHERE extracted='$def'";//GLPI
//echo $reqUpd."
";
mysql_query($reqUpd, $_SESSION["writeServer"]) or die(mysql_error($_SESSION["writeServer"]));
if( mysql_affected_rows() <= 0) {
$reqUpd = "INSERT INTO dico_soft(formatted,extracted) VALUES('$cat', '$def')";//GLPI
//echo $reqUpd."
";
@mysql_query($reqUpd, $_SESSION["writeServer"]);
}
alterChecksum($def);
}
}
function delSoft($def) {
$reqDcat = "DELETE FROM dico_soft WHERE extracted='$def'";//GLPI
mysql_query($reqDcat, $_SESSION["writeServer"]) or die(mysql_error($_SESSION["writeServer"]));
alterChecksum($def);
}
function delIgnored($def) {
$reqDcat = "DELETE FROM dico_ignored WHERE extracted='$def'";
mysql_query($reqDcat, $_SESSION["writeServer"]) or die(mysql_error($_SESSION["writeServer"]));
}
function delCat($cat) {
alterChecksum(false,$cat);
$reqDcat = "DELETE FROM dico_soft WHERE formatted='$cat'";//GLPI
mysql_query($reqDcat, $_SESSION["writeServer"]) or die(mysql_error($_SESSION["writeServer"]));
}
function alterChecksum($ext, $form=false) {
if($ext) {
$_SESSION["toBeMod"][]=$ext;
//$reqCheck = "UPDATE hardware SET checksum=checksum|$softMod WHERE id IN( SELECT hardware_id FROM softwares WHERE name='$ext')";
//mysql_query($reqCheck, $_SESSION["writeServer"]) or die(mysql_error($_SESSION["writeServer"]));
}
else {
$reqSofts = "SELECT DISTINCT(extracted) FROM dico_soft WHERE formatted='$form'";
$resSofts = mysql_query($reqSofts, $_SESSION["writeServer"]) or die(mysql_error($_SESSION["writeServer"]));
while( $valSofts = mysql_fetch_array($resSofts) ) {
alterChecksum($valSofts["extracted"]);
}
}
}
function computeChecksums() {
echo "COMPUTING: ".sizeof($_SESSION["toBeMod"])."
";
flush();
$softMod = "65536";
$reqCheck = "UPDATE hardware SET checksum=checksum|$softMod WHERE id IN (SELECT DISTINCT(hardware_id) FROM softwares WHERE name IN(";
$first = true;
foreach( $_SESSION["toBeMod"] as $soft ) {
if( !$first )
$reqCheck .= ",";
$reqCheck .= "'$soft'";
if( $first ) $first = false;
}
$reqCheck .= "));";
//echo $reqCheck;
mysql_query($reqCheck, $_SESSION["writeServer"]) or die(mysql_error($_SESSION["writeServer"]));
}
?>