Skip to content

Commit ede98e3

Browse files
committed
more php8 updates
1 parent d8b77c8 commit ede98e3

22 files changed

+78
-38
lines changed

classes/Cabinet.class.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
For further details on the license, see http://www.gnu.org/licenses
2424
*/
2525

26+
#[AllowDynamicProperties]
2627
class Cabinet {
2728
/* Cabinet: The workhorse logical container for DCIM. This can be a 2-post rack, a 4-post open rack,
2829
or an enclosed cabinet. The height is variable. Devices are attached to cabinets, and
@@ -65,7 +66,7 @@ function MakeSafe() {
6566
$this->Keylock=sanitize($this->Keylock);
6667
$this->MaxKW=float_sqlsafe(floatval($this->MaxKW));
6768
$this->MaxWeight=intval($this->MaxWeight);
68-
$this->InstallationDate=date("Y-m-d", strtotime($this->InstallationDate));
69+
$this->InstallationDate=($test=$this->InstallationDate)?date("Y-m-d", strtotime($test)):"";
6970
$this->MapX1=abs((is_numeric($this->MapX1)?$this->MapX1:0));
7071
$this->MapY1=abs((is_numeric($this->MapY1)?$this->MapY1:0));
7172
$this->MapX2=abs((is_numeric($this->MapX2)?$this->MapX2:0));
@@ -110,7 +111,7 @@ static function RowToObject($dbRow,$filterrights=true){
110111
$cab->Notes=$dbRow["Notes"];
111112
$cab->U1Position=$dbRow["U1Position"];
112113

113-
switch($config->ParameterArray["AssignCabinetLabels"]){
114+
switch(($test=$config->ParameterArray["AssignCabinetLabels"])?$test:""){
114115
case "OwnerName":
115116
$dept=new Department($cab->AssignedTo);
116117
$dept->GetDeptByID();

classes/DataCenter.class.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -635,12 +635,12 @@ function GetDCStatistics(){
635635
$sql="SELECT AVG(NULLIF(a.Temperature, 0)) as AvgTemp FROM fac_SensorReadings a, fac_Cabinet b, fac_Device c
636636
WHERE a.DeviceID=c.DeviceID and c.Cabinet=b.CabinetID AND c.BackSide=0 AND
637637
b.DataCenterID=$this->DataCenterID;";
638-
$dcStats["AvgTemp"]=($test=round($this->query($sql)->fetchColumn()))?$test:0;
638+
$dcStats["AvgTemp"]=round($test=($this->query($sql)->fetchColumn())?$test:0);
639639

640640
$sql="SELECT AVG(NULLIF(a.Humidity, 0)) as AvgHumidity FROM fac_SensorReadings a, fac_Cabinet b, fac_Device c
641641
WHERE a.DeviceID=c.DeviceID and c.BackSide=0 and c.Cabinet=b.CabinetID AND
642642
b.DataCenterID=$this->DataCenterID;";
643-
$dcStats["AvgHumidity"]=($test=round($this->query($sql)->fetchColumn()))?$test:0;
643+
$dcStats["AvgHumidity"]=round($test=($this->query($sql)->fetchColumn())?$test:0);
644644

645645
$pdu=new PowerDistribution();
646646
$dcStats["MeasuredWatts"]=$pdu->GetWattageByDC($this->DataCenterID);

classes/Device.class.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
For further details on the license, see http://www.gnu.org/licenses
2424
*/
2525

26+
#[AllowDynamicProperties]
2627
class Device {
2728
/* Device: Assets within the data center, at the most granular level. There are three basic
2829
groupings of information kept about a device: asset tracking, virtualization

classes/DeviceTemplate.class.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
2323
For further details on the license, see http://www.gnu.org/licenses
2424
*/
25+
26+
#[AllowDynamicProperties]
2527
class DeviceTemplate {
2628
var $TemplateID;
2729
var $ManufacturerID;

classes/LogActions.class.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ function val_comp($v1, $v2) {
210210
$return=true;
211211

212212
// If a retention period has been set, trim the logs for this ObjectID prior to making this entry
213-
if ( $config->ParameterArray["logretention"] > 0 ) {
213+
if ( isset($config->ParameterArray["logretention"]) && $config->ParameterArray["logretention"] > 0 ) {
214214
LogActions::Prune( $config->ParameterArray["logretention"], $log->ObjectID );
215215
}
216216

@@ -378,14 +378,14 @@ function MakeSafe(){
378378
// If we want to really sanitize this list uncomment the function below
379379
// $this->UserID=(ArraySearchRecursive($this->UserID,$p->GetUserList(),'UserID'))?$this->UserID:'';
380380
$this->UserID=sanitize($this->UserID);
381-
$this->Class=(class_exists($this->Class,true))?$this->Class:'';
381+
$this->Class=$this->Class===null?'':((class_exists($this->Class,true))?$this->Class:'');
382382
$this->ObjectID=sanitize($this->ObjectID);
383383
$this->ChildID=sanitize($this->ChildID);
384384
$this->Action=sanitize($this->Action);
385385
$this->Property=sanitize($this->Property);
386386
$this->OldVal=sanitize($this->OldVal);
387387
$this->NewVal=sanitize($this->NewVal);
388-
$this->Time=date("Y-m-d", strtotime($this->Time));
388+
$this->Time=$this->Time===null?'':date("Y-m-d H:i:s", strtotime($this->Time));
389389
}
390390

391391
function ListUnique($sqlcolumn){

classes/Zone.class.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,13 +279,13 @@ function GetZoneStatistics(){
279279
fac_Device b, fac_Cabinet c WHERE a.DeviceID=b.DeviceID AND b.BackSide=0 and
280280
b.Cabinet=c.CabinetID AND a.DeviceID IN (SELECT b.DeviceID FROM fac_Device
281281
WHERE ZoneID=$this->ZoneID);";
282-
$zoneStats["AvgTemp"]=($test=round($this->query($sql)->fetchColumn()))?$test:0;
282+
$zoneStats["AvgTemp"]=round($test=($this->query($sql)->fetchColumn())?$test:0);
283283

284284
$sql="SELECT AVG(NULLIF(Humidity, 0)) AS AvgHumdity FROM fac_SensorReadings a,
285285
fac_Device b, fac_Cabinet c WHERE a.DeviceID=b.DeviceID AND b.BackSide=0 and
286286
b.Cabinet=c.CabinetID AND a.DeviceID IN (SELECT b.DeviceID FROM fac_Device
287287
WHERE ZoneID=$this->ZoneID);";
288-
$zoneStats["AvgHumidity"]=($test=round($this->query($sql)->fetchColumn()))?$test:0;
288+
$zoneStats["AvgHumidity"]=round($test=($this->query($sql)->fetchColumn())?$test:0);
289289

290290
$sql = "select count(*) from fac_Cabinet where ZoneID=" . intval($this->ZoneID);
291291
$zoneStats["TotalCabinets"]=($test=$this->query($sql)->fetchColumn())?$test:0;

configuration.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,8 @@ function formatOffset($offset) {
403403
$tzmenu.="\t<li>$country\n\t\t<ul>";
404404
foreach($cityarray as $key => $city){
405405
$z=new DateTimeZone($city);
406-
$c=new DateTime(null, $z);
406+
$c=new DateTime();
407+
$c->setTimeZone($z);
407408
$adjustedtime=$c->format('H:i a');
408409
$offset=formatOffset($z->getOffset($c));
409410
$tzmenu.="\t\t\t<li><a href=\"#\" data=\"$city\">$adjustedtime - $offset $city</a></li>\n";

devices.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ function updatedevice($devid){
559559
$cab->GetCabinet();
560560
if($person->canWrite($cab->AssignedTo)){
561561
$wattage=$pdu->LogManualWattage($_POST["currwatts"]);
562-
$wattage->LastRead=strftime("%c",strtotime($wattage->LastRead));
562+
$wattage->LastRead=date("Y-m-d H:i:s",strtotime($wattage->LastRead));
563563
}
564564
}
565565
header('Content-Type: application/json');
@@ -825,7 +825,7 @@ function updatedevice($devid){
825825

826826
$lastreading=$pdu->GetLastReading();
827827
$LastWattage=($lastreading)?$lastreading->Wattage:0;
828-
$LastRead=($lastreading)?strftime("%c",strtotime($lastreading->LastRead)):"Never";
828+
$LastRead=($lastreading)?date("Y-m-d H:i:s",strtotime($lastreading->LastRead)):"Never";
829829
}
830830
}
831831

fpdf.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,22 @@ function __construct($orientation='P', $unit='mm', $size='A4')
138138
$this->DefOrientation = 'P';
139139
$this->w = $size[0];
140140
$this->h = $size[1];
141+
if($this->w > $this->h) { // Ensure the page is portrait
142+
$temp = $this->w;
143+
$this->w = $this->h
144+
$this->h = $temp;
145+
}
141146
}
142147
elseif($orientation=='l' || $orientation=='landscape')
143148
{
144149
$this->DefOrientation = 'L';
145150
$this->w = $size[1];
146151
$this->h = $size[0];
152+
if($this->w < $this->h) { // Ensure the page is landscape
153+
$temp = $this->w;
154+
$this->w = $this->h
155+
$this->h = $temp;
156+
}
147157
}
148158
else
149159
$this->Error('Incorrect orientation: '.$orientation);
@@ -575,8 +585,9 @@ function AcceptPageBreak()
575585

576586
function Cell($w, $h=0, $txt='', $border=0, $ln=0, $align='', $fill=false, $link='')
577587
{
578-
$txt=utf8_decode($txt); // Comment this line and uncomment the next line to use TrueType fonts from loadfonts.php
579-
// $txt=iconv("UTF-8","Windows-1251",$txt);
588+
if($txt === null) $txt = "";
589+
$txt=iconv("UTF-8","Windows-1251",$txt); // Comment this line and uncomment the next line to not use TrueType fonts from loadfonts.php
590+
//$txt=utf8_decode($txt);
580591
// Output a cell
581592
$k = $this->k;
582593
if($this->y+$h>$this->PageBreakTrigger && !$this->InHeader && !$this->InFooter && $this->AcceptPageBreak())

power_panel.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
if(isset($_POST["action"])&&(($_POST["action"]=="Create")||($_POST["action"]=="Update")||($_POST["action"]=="Map"))){
3838
foreach($panel as $prop => $val){
39-
$panel->$prop=trim($_POST[$prop]);
39+
$panel->$prop=isset($_POST[$prop])?trim($_POST[$prop]):'';
4040
}
4141
// Coordinates aren't displayed on this page and the loop above is looking
4242
// for every attribute on the panel model. This will load the original object
@@ -76,7 +76,7 @@ function FindTicks(&$decimalplaces,$panelCap,&$dataMajorTicks){
7676
$panelCap=1;
7777
}
7878
for ( $i = 0; ($i - $panelCap) < 1; $i+=( $panelCap / 10 ) ) {
79-
$tick = sprintf( "%.0${decimalplaces}lf ", $i / 1000 );
79+
$tick = sprintf( "%.0{$decimalplaces}lf ", $i / 1000 );
8080
if(preg_match("/$tick/",$dataMajorTicks)){
8181
$err=true;
8282
break;
@@ -90,16 +90,16 @@ function FindTicks(&$decimalplaces,$panelCap,&$dataMajorTicks){
9090
$dataMajorTicks = "";
9191
}
9292

93-
$dataMaxValue = sprintf( "%.0${decimalplaces}lf", $panelCap / 1000 );
93+
$dataMaxValue = sprintf( "%.0{$decimalplaces}lf", $panelCap / 1000 );
9494

9595
$dataHighlights = sprintf( "0 %d #eee, %d %d #fffacd, %d %d #eaa", $panelCap / 1000 * .6, $panelCap / 1000 * .6, $panelCap / 1000 * .8, $panelCap / 1000 * .8, $panelCap / 1000);
9696

9797
$mtarray=implode(",",explode(" ",$dataMajorTicks));
98-
$hilights = sprintf( "{from: 0, to: %.0${decimalplaces}lf, color: '#eee'}, {from: %.0${decimalplaces}lf, to: %.0${decimalplaces}lf, color: '#fffacd'}, {from: %.0${decimalplaces}lf, to: %.0${decimalplaces}lf, color: '#eaa'}", $panelCap / 1000 * .6, $panelCap / 1000 * .6, $panelCap / 1000 * .8, $panelCap / 1000 * .8, $panelCap / 1000);
98+
$hilights = sprintf( "{from: 0, to: %.0{$decimalplaces}lf, color: '#eee'}, {from: %.0{$decimalplaces}lf, to: %.0{$decimalplaces}lf, color: '#fffacd'}, {from: %.0{$decimalplaces}lf, to: %.0{$decimalplaces}lf, color: '#eaa'}", $panelCap / 1000 * .6, $panelCap / 1000 * .6, $panelCap / 1000 * .8, $panelCap / 1000 * .8, $panelCap / 1000);
9999

100-
$panelLoad = sprintf( "%.0${decimalplaces}lf", PowerPanel::getInheritedLoad($panel->PanelID) / 1000 );
101-
$msrLoad = sprintf( "%.0${decimalplaces}lf", $panel->getPanelLoad() / 1000 );
102-
$estLoad = sprintf( "%.0${decimalplaces}lf", PowerPanel::getEstimatedLoad($panel->PanelID) / 1000 );
100+
$panelLoad = sprintf( "%.0{$decimalplaces}lf", PowerPanel::getInheritedLoad($panel->PanelID) / 1000 );
101+
$msrLoad = sprintf( "%.0{$decimalplaces}lf", $panel->getPanelLoad() / 1000 );
102+
$estLoad = sprintf( "%.0{$decimalplaces}lf", PowerPanel::getEstimatedLoad($panel->PanelID) / 1000 );
103103

104104
// Generate JS for load display
105105

0 commit comments

Comments
 (0)