.
*
* ------------------------------------------------------------------------
*
* This file is used to manage the general display in plugin.
*
* ------------------------------------------------------------------------
*
* @package FusionInventory
* @author Vincent Mazzoni
* @author David Durieux
* @copyright Copyright (c) 2010-2016 FusionInventory team
* @license AGPL License 3.0 or (at your option) any later version
* http://www.gnu.org/licenses/agpl-3.0-standalone.html
* @link http://www.fusioninventory.org/
* @link https://github.com/fusioninventory/fusioninventory-for-glpi
*
*/
if (!defined('GLPI_ROOT')) {
die("Sorry. You can't access directly to this file");
}
/**
* Manage the general display in plugin.
*/
class PluginFusioninventoryDisplay extends CommonDBTM {
/**
* Display static progress bar (used for SNMP cartridge state)
*
* @param integer $percentage
* @param string $message
* @param string $order
* @param integer $width
* @param integer $height
*/
static function bar($percentage, $message = '', $order = '', $width = '400', $height = '20') {
if ((!empty($percentage)) AND ($percentage < 0)) {
$percentage = "";
} else if ((!empty($percentage)) AND ($percentage > 100)) {
$percentage = "";
}
echo "
";
if ((!empty($percentage))
|| ($percentage == "0")) {
echo $percentage."% ".$message;
}
echo " |
|
";
if (empty($percentage)) {
echo " | ";
} else {
echo " 80) {
echo "red";
} else if ($percentage > 60) {
echo "orange";
} else {
echo "green";
}
} else {
if ($percentage < 20) {
echo "red";
} else if ($percentage < 40) {
echo "orange";
} else {
echo "green";
}
}
if ($percentage == 0) {
echo "' height='".$height."' width='1'> | ";
} else {
echo "' height='".$height."' width='".(($width * $percentage) / 100)."'> ";
}
}
if ($percentage == 0) {
echo " | ";
} else {
echo " | ";
}
echo "
|
";
}
/**
* Disable debug mode to not see php errors
*/
static function disableDebug() {
error_reporting(0);
set_error_handler(['PluginFusioninventoryDisplay', 'error_handler']);
}
/**
* Enable debug mode if user is in debug mode
**/
static function reenableusemode() {
Toolbox::setDebugMode();
}
/**
* When debug is disabled, we transfer every errors in this emtpy function.
*
* @param integer $errno
* @param string $errstr
* @param string $errfile
* @param integer $errline
*/
static function error_handler($errno, $errstr, $errfile, $errline) {
}
/**
* Display progress bar
*
* @global array $CFG_GLPI
* @param integer $width
* @param integer $percent
* @param array $options
* @return string
*/
static function getProgressBar($width, $percent, $options = []) {
global $CFG_GLPI;
$param = [];
$param['title']=__('Progress', 'fusioninventory');
$param['simple']=false;
$param['forcepadding']=false;
if (is_array($options) && count($options)) {
foreach ($options as $key => $val) {
$param[$key]=$val;
}
}
$percentwidth=floor($percent*$width/100);
$output="";
if (!$param['simple']) {
$output.="".$param['title']." ".$percent."% |
";
}
$output.="
";
if ($param['simple']) {
$output.=$percent."%";
} else {
$output.=' ';
}
$output.=" |
| ";
$output.="
";
$output.="
";
return $output;
}
}