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
|
<?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 for software categories
*/
class SoftwareCategory
{
public $html;
/**
* Get all categories for onglet
* @return array
*/
public function onglet_cat(){
$sql_list_cat = "SELECT `ID`, `CATEGORY_NAME` FROM `software_categories`";
$result_list_cat = mysqli_query($_SESSION['OCS']["readServer"], $sql_list_cat);
$i = 1;
while ($item_list_cat = mysqli_fetch_array($result_list_cat)) {
if ($i == 1) {
$list_cat['first_onglet'] = $i;
}
$list_cat[$i] = $item_list_cat['CATEGORY_NAME'];
$list_cat['category_name'][$item_list_cat['CATEGORY_NAME']] = $item_list_cat['ID'];
$i++;
}
$list_cat['i'] = $i;
return ($list_cat);
}
/**
* Insert new category
* @param string $catName
* @return boolean
*/
public function add_category($catName){
$sql_verif = "SELECT `CATEGORY_NAME` FROM `software_categories` WHERE `CATEGORY_NAME` = '%s'";
$arg_verif = array($catName);
$result_verif = mysql2_query_secure($sql_verif, $_SESSION['OCS']["readServer"], $arg_verif);
$item = mysqli_fetch_array($result_verif);
if($item != null){
return(false);
}else{
$sql = "INSERT INTO `software_categories` (`CATEGORY_NAME`) values('%s');";
$arg_sql = array($catName);
$result = mysql2_query_secure($sql, $_SESSION['OCS']["writeServer"], $arg_sql);
return ($result);
}
}
/**
* Search all categories
* @return array
*/
public function search_all_cat(){
$sql_list_cat = "SELECT `ID`, `CATEGORY_NAME` FROM `software_categories`";
$result_list_cat = mysqli_query($_SESSION['OCS']["readServer"], $sql_list_cat);
$list_cat[0] = " ";
while ($item_list_cat = mysqli_fetch_array($result_list_cat)) {
$list_cat[$item_list_cat['ID']] = $item_list_cat['CATEGORY_NAME'];
}
return ($list_cat);
}
/**
* Insert RegEx
* @param int $id_cat
* @param string $regExp
* @return boolean
*/
public function insert_exp($id_cat, $regExp){
$sql_reg = "INSERT INTO `software_category_exp` (`CATEGORY_ID`, `SOFTWARE_EXP`) values(%s, '%s')";
$arg_reg = array($id_cat, $regExp);
$result = mysql2_query_secure($sql_reg, $_SESSION['OCS']["writeServer"], $arg_reg);
return ($result);
}
/**
* get regEx values for table
* @param protectedPost $onglet_active
* @return array
*/
public function display_reg($onglet_active){
$sql = "SELECT `SOFTWARE_EXP` FROM `software_category_exp` WHERE `CATEGORY_ID`= '%s'";
$arg_sql = array($onglet_active);
$result = mysql2_query_secure($sql, $_SESSION['OCS']["readServer"], $arg_sql);
while ($item = mysqli_fetch_array($result)) {
$list[] = $item['SOFTWARE_EXP'];
}
return ($list);
}
public function get_table_html_soft(){
global $l;
$cat = $this->search_all_cat();
unset($cat['0']);
$this->html = '<table 0="[object Object]" 1="[object Object]" 2="[object Object]" border="0" style="cellspacing:0;color:#000;font-family:Roboto, Helvetica, sans-serif;font-size:13px;line-height:22px;table-layout:auto;width:100%;">
<tr style="border-bottom:1px solid #ecedee; border-left:1px solid #ecedee; border-right:1px solid #ecedee;border-top:1px solid #ecedee; text-align:center;padding:15px 0;">
<th style="padding: 0 15px 0 0; text-align:center;">'.$l->g(49).'</th>
<th style="padding: 0 0 0 15px; text-align:center;">'.$l->g(2131).'</th>
</tr>';
foreach ($cat as $key => $value){
$sql = "SELECT DISTINCT `NAME` FROM softwares WHERE CATEGORY = %s";
$arg = array($key);
$result = mysql2_query_secure($sql, $_SESSION['OCS']["readServer"], $arg);
while ($computer = mysqli_fetch_array($result)) {
$nb[$value][] = $computer['NAME'];
}
$nb_computer[$value] = count($nb[$value]);
}
foreach($nb_computer as $name => $nb){
$this->html .= '<tr style="border-bottom:1px solid #ecedee; border-left:1px solid #ecedee; border-right:1px solid #ecedee;text-align:center;padding:15px 0;">
<td style="padding: 0 15px 0 0;">'.$name.'</td>
<td style="padding: 0 0 0 15px;">'.$nb.'</td>
</tr>';
}
$this->html .= '</table>';
return $this->html;
}
}
|