=2147483647 ORDER BY runrangeid DESC LIMIT 1"; $query = "SELECT runrangeid,minRun,maxRun FROM RunRange WHERE maxRun>=2147483647 AND runrangeid=27 ORDER BY runrangeid DESC LIMIT 1"; $res = $db->query($query); $row = $res->fetch(PDO::FETCH_ASSOC); $runrangeid = $row['runrangeid']; $minRun = $row['minRun']; $maxRun = $row['maxRun']; if( $maxRun >= 2147483647) { $maxRun = "inf";} }catch(PDOException $e) { // Print PDOException message echo $e->getMessage(); } //--------------------- // ShowTable //--------------------- function ShowTable($tablename, $caller_where="") { global $runrangeid, $tables; // 2023-08-22 David Lawrence // This addresses a vulnerability idntified by JLab Cybersecurity // (Cameron Allen) where an SQL injection was possible via the // table name. This will check if the requested $tablename is actually // one of the tables before doing anything with it. if (!in_array($tablename, $tables)) { print "

Unknown table name specified.

"; return; } //$tables = $tablename; $where = "WHERE runrangeid=$runrangeid"; if($caller_where != "") $where = "$where AND ($caller_where)"; // First, check at least 1 row will be returned since we can do nothing // without at least one row. It seems like we should be able to get // this from the actual query below, but web documentation says this // is the proper and portable way. global $db; $query = "SELECT count(*) FROM $tablename $where"; if($res = $db->query($query)){ if ($res->fetchColumn() == 0) { print "

No Entries

"; return; } }else{ print "

No table named \"$tablename\"

"; return; } // query the table $query = "SELECT * FROM $tablename $where"; $res = $db->query($query); // Get column names $row = $res->fetch(PDO::FETCH_ASSOC); $cols = array_keys($row); // Make table with column names as headers $str = "\n"; $str .= "\n"; $str .= "\n"; foreach($cols as $col){ $str .= "\n"; } $str .= "\n"; // Enter first row of data $str .= "\n"; $vals = array_values($row); foreach($row as $col => $val){ if(strstr($col, "_chanid") !== false){ $val = "$val"; } if(strstr($col,"_chanid") === FALSE){$bgcolor = "#EECCCC";}else{$bgcolor = "#FFEEEE";} $str .= "\n"; } $str .= "\n"; // Enter remaining rows while($row = $res->fetch(PDO::FETCH_ASSOC)){ $str .= "\n"; foreach($row as $col => $val){ if(strstr($col, "_chanid") !== false){ $val = "$val"; } if(strstr($col,"_chanid") === FALSE){$bgcolor = "#EECCCC";}else{$bgcolor = "#FFEEEE";} $str .= "\n"; } $str .= "\n"; } // return results return $str; } $module_color["fADC250"] = "#FF2222"; $module_color["fADC125"] = "#EE4444"; $module_color["F1TDCV2"] = "#22FF22"; $module_color["F1TDCV3"] = "#44DD44"; $module_color["TI"] = "#DDDDFF"; $module_color["CTP"] = "#DDFFFF"; $module_color["SSP"] = "#FFDDFF"; $module_color["CPU"] = "#FFFFDD"; //----------------------- // DrawCrate //----------------------- function DrawCrate($area, $rack, $location) { // Initialize list of modules to empty $module_types = array(); $moduleids = array(); for($slot=0; $slot<=21; $slot++){ $module_types[$slot] = "empty"; $moduleids[$slot] = -1; } // Get list of modules in each slot global $db; $query = "SELECT moduleid,slot,type FROM Module,Crate WHERE Module.crateid=Crate.crateid AND area='$area' AND rack=$rack AND location='$location'"; if($res = $db->query($query)){ while($row = $res->fetch(PDO::FETCH_ASSOC)){ $slot = $row["slot"]; if($slot>0 && $slot<=21){ $type = $row["type"]; $module_types[$slot] = $row["type"]; $moduleids[$slot] = $row["moduleid"]; } } } // Draw crate using HTML table $str = "
$tablename
$col
$val
$val
"; $str .= "\n"; global $module_color; for($slot=1; $slot<=21; $slot++){ $type = $module_types[$slot]; $moduleid = $moduleids[$slot]; if($type == "empty"){ $color = "#222222"; $content = "_"; }else{ $color = "#999999"; if(isset($module_color[$type])) $color = $module_color[$type]; $content = ""; for($i=0; $i"; $content .= ""; } $str .= "\n"; } $str .= "\n"; $str .= "
$area-$rack-$location
$content
\n"; return $str; } //----------------------- // DrawRack //----------------------- function DrawRack($area, $rack) { // Get list of crates in this rack global $db; $crate_locs = array(); $crate_locs["TOP"] = $crate_locs["MID"] = $crate_locs["BOT"] = FALSE; $query = "SELECT crateid,location FROM Crate WHERE area='$area' AND rack=$rack"; if($res = $db->query($query)){ while($row = $res->fetch(PDO::FETCH_ASSOC)){ $crate_locs[$row["location"]] = TRUE; } } $str = ""; $str .= "\n"; // TOP $str .= ""; // MID $str .= ""; // BOT $str .= ""; $str .= "\n"; $str .= "
"; if($crate_locs["TOP"]){ $str .= DrawCrate($area, $rack, "TOP"); }else{ $str .= " "; } $str .= "
"; if($crate_locs["MID"]){ $str .= DrawCrate($area, $rack, "MID"); }else{ $str .= " "; } $str .= "
"; if($crate_locs["BOT"]){ $str .= DrawCrate($area, $rack, "BOT"); }else{ $str .= " "; } $str .= "
\n"; return $str; } //----------------------- // DrawModule //----------------------- function DrawModule($moduleid) { global $db, $runrangeid; // Get the next and previous moduleid values $moduleid_prev = $moduleid; $moduleid_next = $moduleid; if($res = $db->query("SELECT moduleid FROM Module WHERE moduleid<$moduleid ORDER BY moduleid DESC LIMIT 1")){ $row = $res->fetch(PDO::FETCH_ASSOC); $moduleid_prev = $row["moduleid"]; } if($res = $db->query("SELECT moduleid FROM Module WHERE moduleid>$moduleid ORDER BY moduleid LIMIT 1")){ $row = $res->fetch(PDO::FETCH_ASSOC); $moduleid_next = $row["moduleid"]; } // Get the column names for the detector specific indexing // and at same time, get list of chanid column names for use later $col_names = array(); // non-chanid columns $chanid_cols = array(); // chanid columns $res = $db->query("SELECT system FROM Channel WHERE moduleid=$moduleid AND Channel.runrangeid=$runrangeid LIMIT 1"); $row = $res->fetch(PDO::FETCH_ASSOC); $system = $row["system"]; if ($res = $db->query("SELECT * FROM $system LIMIT 1")){ $row = $res->fetch(PDO::FETCH_ASSOC); $tmp = array_keys($row); foreach($tmp as $a){ if (strpos($a, 'chanid') === FALSE) { $col_names[] = $a; }else{ $chanid_cols[] = $a; } } } // Print previous and next buttons $prev = "<prev"; $next = "next>"; if($moduleid_prev == $moduleid) $prev = "<prev"; // disable link if($moduleid_next == $moduleid) $next = "next>"; // disable link $str = ""; $str .= "
"; $str .= ""; $str .= "
$prev$next
"; // Print header $str .= ""; $str .= "\n"; $str .= ""; $str .= ""; $str .= ""; foreach($col_names as $col_name){ $str .= ""; } $str .= "\n"; $query = "SELECT * FROM Channel,RunRange WHERE moduleid=$moduleid AND Channel.runrangeid=RunRange.runrangeid and RunRange.runrangeid=$runrangeid ORDER BY channel"; if($res = $db->query($query)){ while($row = $res->fetch(PDO::FETCH_ASSOC)){ $chanid = $row["chanid"]; $col_name = $row["col_name"]; $system = $row["system"]; $name = $row["name"]; $channel = $row["channel"]; // Get detector specific indicies from system table $row2 = array(); $where = "1=2"; foreach($chanid_cols as $chanid_col) $where .= " OR $chanid_col=$chanid"; $where .= " AND runrangeid=$runrangeid"; $query = "SELECT * FROM $system WHERE $where"; if($res2 = $db->query($query)){ $row2 = $res2->fetch(PDO::FETCH_ASSOC); } $str .= ""; $str .= ""; foreach($col_names as $col_name){ $str .= ""; } $str .= ""; } } $str .= "\n"; $str .= "
connectorname$col_name
$channel$name".$row2[$col_name]."
\n"; return $str; } //----------------------- // DrawArea //----------------------- function DrawArea($area) { global $db; $headers = ""; $racks_str = ""; // Some areas have the rack numbering go left to right when viewing from front // of racks and others are right to left. $sort_order = "ASC"; $reversed_areas = array("N1"); if(in_array($area, $reversed_areas)) { $sort_order = "DESC";} $query = "SELECT rack FROM Crate WHERE area='$area' GROUP BY rack ORDER BY rack $sort_order"; if($res = $db->query($query)){ while($row = $res->fetch(PDO::FETCH_ASSOC)){ $rack = $row["rack"]; $headers .= "Rack $rack"; $racks_str .= "".DrawRack($area, $rack).""; } } $str = ""; $str .= "\n"; $str .= "$headers"; $str .= "$racks_str"; $str .= "\n"; $str .= "
\n"; return $str; } ?>