remove class portlist
authorgithub138 <m.ehinger@ltur.de>
Fri, 15 Jul 2016 06:53:26 +0000 (08:53 +0200)
committergithub138 <m.ehinger@ltur.de>
Fri, 15 Jul 2016 06:54:19 +0000 (08:54 +0200)
LinkManagement/plugins/linkmgmt.php

index bc5db64..dd2f60d 100644 (file)
@@ -1,7 +1,6 @@
 <?php
 // TODO linkchain cytoscape create libs?
 //     linkchain all objects graph cytoscape takes ages
-//     avoid create own linkchain for every port on global map
 //     highlight port cytoscape maps
 /*
  * Link Management for RT >= 0.20.9
@@ -4644,737 +4643,4 @@ JSEND
 
 /* -------------------------------------------------- */
 
-/*
- * Portlist class
- * gets all linked ports to spezified port
- * and prints this list as table row
- *
- */
-class portlist {
-
-       public $list = array();
-
-       private $object_id;
-       private $port_id;
-       private $port;
-
-       private $first_id;
-       private $front_count;
-
-       private $last_id;
-       private $back_count;
-
-       private $count = 0;
-
-       private $allback = FALSE;
-
-       private $multilink = LM_MULTILINK;
-
-       const B2B_LINK_BGCOLOR = '#d8d8d8';
-       const CURRENT_PORT_BGCOLOR = '#ffff99';
-       const CURRENT_OBJECT_BGCOLOR = '#ff0000';
-       const HL_PORT_BGCOLOR = '#00ff00';
-       const ALTERNATE_ROW_BGCOLOR = '#f0f0f0';
-
-       /* Possible LOOP detected after count links print only */
-       const MAX_LOOP_COUNT = 13;
-
-       private $loopcount;
-
-       private $gv = NULL;
-
-       function __construct($port, $object_id, $allports = FALSE, $allback = FALSE) {
-
-               $this->object_id = $object_id;
-
-               $this->port = $port;
-
-               $port_id = $port['id'];
-
-               $this->port_id = $port_id;
-
-               $this->first_id = $port_id;
-               $this->last_id = $port_id;
-
-               $this->allback = $allback;
-
-               $this->_getportlists($port_id);
-
-               if(!$allports)
-                       if($this->count == 0 || ( ($this->count == 1) && (!empty($this->list[$port_id]['back'])) ) ) {
-                               $this->list = array();
-                               $this->first_id = NULL;
-                       }
-
-       //      $this->var_dump_html($this->list);
-
-       } /* __construct */
-
-
-       /*
-        * get front and back portlist
-        */
-       function _getportlists($port_id) {
-
-               /* Front Port */
-               $this->count = 0;
-               $this->_getportlist($this->_getportdata($port_id),FALSE, TRUE);
-               $this->front_count = $this->count;
-
-               /* Back Port */
-               $this->count = 0;
-               $this->_getportlist($this->_getportdata($port_id), TRUE, FALSE);
-               $this->back_count = $this->count;
-
-               $this->count = $this->front_count + $this->back_count;
-       }
-
-       /*
-         * gets front or back port of src_port
-        * and adds it to the list
-        */
-       /* !!! recursive */
-       function _getportlist(&$src_port, $back = FALSE, $first = TRUE) {
-
-               $src_port_id = $src_port['id'];
-
-               if($back)
-                       $linktype = 'back';
-               else
-                       $linktype = 'front';
-
-               if(!empty($src_port[$linktype])) {
-
-                       /* multilink */
-                       foreach($src_port[$linktype] as &$src_link) {
-                               $dst_port_id = $src_link['id'];
-
-                               if(!$this->_loopdetect($src_port,$dst_port_id,$src_link,$linktype)) {
-                                       //error_log("no loop $linktype>".$dst_port_id);
-                                       $this->count++;
-                                       $this->_getportlist($this->_getportdata($dst_port_id), !$back, $first);
-                               }
-                       }
-
-               } else {
-                       if($first) {
-                               $this->first_id = $src_port_id;
-                       //      $this->front_count = $this->count; /* doesn't work on loops */
-                       } else {
-                               $this->last_id = $src_port_id;
-                       //      $this->back_count = $this->count; /* doesn't work on loops */
-                       }
-
-               }
-
-       } /* _getportlist */
-
-       /*
-        * as name suggested
-        */
-       function _loopdetect(&$src_port, $dst_port_id, &$src_link, $linktype) {
-
-               /* TODO multilink*/
-               if(array_key_exists($dst_port_id, $this->list)) {
-
-               //      $dst_port = $this->list[$dst_port_id];
-
-                       //echo "LOOP :".$src_port['id']."-->".$dst_port_id;
-
-                       /* print loop at least once */
-                       if($dst_port_id == $this->port_id)
-                       {
-                               $src_link['loop'] = $dst_port_id;
-                               return TRUE;
-                       }
-
-               }
-
-               return FALSE;
-
-       } /* _loopdetect */
-
-       /*
-        * get all data for one port
-        *      name, object, front link, back link
-        */
-       function &_getportdata($port_id) {
-               /* sql bitwise xor: porta ^ portb */
-               //select cable, ((porta ^ portb) ^ 4556) as port from Link where (4556 in (porta, portb));
-
-               //error_log("_getportdata $port_id");
-
-               /* TODO single sql ? */
-
-               $result = usePreparedSelectBlade
-               (
-                       'SELECT Port.id, Port.name, Port.label, Port.type, Port.l2address, Port.object_id, Port.reservation_comment,
-                                       Object.name as "obj_name"
-                                from Port
-                                join Object on Object.id = Port.object_id
-                                where Port.id = ?',
-                               array($port_id)
-               );
-               $datarow = $result->fetchAll(PDO::FETCH_ASSOC);
-
-               $result->closeCursor();
-               unset($result);
-
-               $result = usePreparedSelectBlade
-               (
-                               'SELECT Port.id, Link.cable, Port.name, Port.label, Port.type, Port.l2address, Port.object_id,
-                                CONCAT(Link.porta,"_",Link.portb) as link_id from Link
-                                join Port
-                                where (? = Link.porta or ? = Link.portb) and ((Link.porta ^ Link.portb) ^ ? ) = Port.id',
-                               array($port_id, $port_id, $port_id)
-               );
-               $frontrow = $result->fetchAll(PDO::FETCH_ASSOC);
-
-               $result->closeCursor();
-               unset($result);
-
-               $result = usePreparedSelectBlade
-               (
-                               'SELECT Port.id, LinkBackend.cable, Port.name, Port.label, Port.type, Port.l2address, Port.object_id,
-                                CONCAT(LinkBackend.porta,"_",LinkBackend.portb,"_back") as link_id from LinkBackend
-                                join Port
-                                where (? = LinkBackend.porta or ? = LinkBackend.portb) and ((LinkBackend.porta ^ LinkBackend.portb) ^ ? ) = Port.id',
-                               array($port_id, $port_id, $port_id)
-               );
-               $backrow = $result->fetchAll(PDO::FETCH_ASSOC);
-
-               $result->closeCursor();
-               unset($result);
-
-               $retval = $datarow[0];
-
-               if(!empty($frontrow))
-                       $retval['front']= $frontrow;
-               else
-                       $retval['front'] = array();
-
-               if(!empty($backrow))
-                       $retval['back'] = $backrow;
-               else
-                       $retval['back'] = array();
-
-       //      $this->var_dump_html($retval);
-
-               /* return reference */
-               $this->list[$port_id] = &$retval;
-
-               return $retval;
-
-       } /* _getportdata */
-
-       /*
-        */
-       function printport(&$port, $multilink = false) {
-               global $lm_cache;
-
-               /* set bgcolor for current port */
-               if($port['id'] == $this->port_id) {
-                       $bgcolor = 'bgcolor='.self::CURRENT_PORT_BGCOLOR;
-                       $idtag = ' id='.$port['id'];
-               } else {
-                       $bgcolor = '';
-                       $idtag = '';
-               }
-
-               $mac = trim(preg_replace('/(..)/','$1:',$port['l2address']),':');
-
-               $title = "Label: ${port['label']}\nMAC: $mac\nTypeID: ${port['type']}\nPortID: ${port['id']}";
-
-               echo '<td'.$idtag.' align=center '.$bgcolor.' title="'.$title.'"><pre>[<a href="'
-                       .makeHref(array('page'=>'object', 'tab' => 'linkmgmt', 'object_id' => $port['object_id'], 'hl_port_id' => $port['id']))
-                       .'#'.$port['id']
-                       .'">'.$port['name'].'</a>]</pre>'.($multilink && $lm_cache['allowbacklink'] ? $this->_getlinkportsymbol($port['id'], 'back') : '' ).'</td>';
-
-       } /* printport */
-
-       /*
-        */
-       function printcomment(&$port) {
-
-               if(!empty($port['reservation_comment'])) {
-                       $prefix = '<b>Reserved: </b>';
-               } else
-                       $prefix = '';
-
-               echo '<td>'.$prefix.'</td><td><i><span class="portlist editable op-upd-reservation-port id-'.$port['id'].'">'.$port['reservation_comment'].'</span</i></td>';
-
-       } /* printComment */
-
-
-       /*
-        */
-       function printobject($object_id, $object_name) {
-               if($object_id == $this->object_id) {
-                        $color='color: '.self::CURRENT_OBJECT_BGCOLOR;
-                } else {
-                        $color='';
-                }
-
-                echo '<td><table align=center cellpadding=5 cellspacing=0 border=1><tr><td align=center><a style="font-weight:bold;'
-                        .$color.'" href="'.makeHref(array('page'=>'object', 'tab' => 'linkmgmt', 'object_id' => $object_id))
-                        .'"><pre>'.$object_name.'</pre></a><pre>'.$this->_getRackInfo($object_id, 'font-size:80%')
-                        .'</pre></td></tr></table></td>';
-
-       } /* printobject */
-
-       /*
-        */
-       function printlink($src_port_id, &$dst_link, $linktype) {
-
-               if($linktype == 'back')
-                       $arrow = '====>';
-               else
-                       $arrow = '---->';
-
-               /* link */
-               echo '<td align=center>';
-
-               echo '<pre><span class="portlist editable id1-'.$src_port_id.' id2-'.$dst_link['id'].' op-lm-upd-reservation-cable linktype-'.$linktype.'">'.$dst_link['cable']
-                       ."</a></pre><pre>$arrow</pre>"
-                       .$this->_printUnLinkPort($src_port_id, $dst_link, $linktype);
-
-               echo '</td>';
-       } /* printlink */
-
-       /*
-        * print cableID dst_port:dst_object
-        */
-       function _printportlink($src_port_id, $dst_port_id, &$dst_link, $back = FALSE) {
-
-               global $lm_multilink_port_types;
-
-               $multilink = LM_MULTILINK;
-
-       if(!isset($this->list[$dst_port_id]))
-       {
-               /* get port not in list */
-       //      echo "<td>AHHH $src_port_id $dst_port_id --> $back</td>";
-       //      echo "<td>load".$this->var_dump_html($dst_link)." tree</td>";
-//             echo "<td>".$dst_link['cable']." ".$dst_link['name']."</td><td>not displayed</td>";
-
-               if($back)
-                       echo "<td>></td>";
-
-               // TODO check if multilink is needed here
-               $this->printport($dst_link, $multilink && in_array($dst_link['type'], $lm_multilink_port_types));
-               echo "<td>...</td>";
-
-               return TRUE;
-
-       //      $this->_getportlist($this->list[$src_port_id], $back, !$back);
-       }
-
-       $dst_port = $this->list[$dst_port_id];
-       $object_id = $dst_port['object_id'];
-       $obj_name = $dst_port['obj_name'];
-
-       if($obj_name == NULL)
-       {
-               $tmpobj = spotEntity('object', $dst_port['object_id']);
-               $dst_port['obj_name'] = $tmpobj['dname'];
-               $obj_name = $tmpobj['dname'];
-       }
-
-       $loop = FALSE;
-       $edgeport = ($dst_link == NULL) || empty($dst_port['front']) || empty($dst_port['back']);
-
-       if($back) {
-               $linktype = 'back';
-       } else {
-               $linktype = 'front';
-       }
-
-       $sameobject = FALSE;
-
-       if(isset($dst_link['loop']))
-               $loop = TRUE;
-
-       if($dst_link != NULL) {
-
-               $src_object_id = $this->list[$src_port_id]['object_id'];
-
-               if(!$this->allback && $object_id == $src_object_id && $back) {
-                       $sameobject = TRUE;
-               } else {
-                       $this->printlink($src_port_id, $dst_link, $linktype);
-               }
-
-       } else {
-               $this->_printlinkportsymbol($dst_port_id, $linktype);
-               $edgeport = true;
-
-                       if(!$back)
-                               $this->printcomment($dst_port);
-               }
-
-               if($back) {
-                       if(!$sameobject)
-                               $this->printobject($object_id,$obj_name);
-
-                       echo "<td>></td>";
-
-                       /* align ports nicely */
-                       if($dst_port['id'] == $this->port_id)
-                               echo '</td></tr></table id=printportlink1></td><td><table align=left><tr>';
-               }
-
-               /* print [portname] */
-               // TODO check multilink symbols front/back edgeports
-               $this->printport($dst_port, $multilink && in_array($dst_port['type'], $lm_multilink_port_types));
-
-               if($loop)
-                       echo '<td bgcolor=#ff9966>LOOP</td>';
-
-               if(!$back) {
-
-                       /* align ports nicely */
-                       if($dst_port['id'] == $this->port_id)
-                               echo '</td></tr></table id=printportlink2></td><td><table align=left><tr>';
-
-                       echo "<td><</td>";
-                       $this->printobject($object_id,$obj_name);
-
-                       if(empty($dst_port['back']))
-                               $this->_printlinkportsymbol($dst_port_id, 'back');
-               } else
-                       if(empty($dst_port['front'])) {
-                               $this->printcomment($dst_port);
-                               $this->_printlinkportsymbol($dst_port_id, 'front');
-                       }
-
-               if($loop) {
-                       if(isset($dst_link['loopmaxcount']))
-                               $reason = " (MAX LOOP COUNT reached)";
-                       else
-                               $reason = '';
-
-                       showWarning("Possible Loop on Port ($linktype) ".$dst_port['name'].$reason);
-                       return FALSE;
-               }
-
-               return TRUE;
-
-       } /* _printportlink */
-
-       /*
-        * print <tr>..</tr>
-        */
-       function printportlistrow($first = TRUE, $hl_port_id = NULL, $rowbgcolor = '#ffffff') {
-
-               $this->loopcount = 0;
-
-               if($this->first_id == NULL)
-                       return false;
-
-               if($first)
-                       $id = $this->first_id;
-               else
-                       $id = $this->last_id;
-
-               if($hl_port_id == $this->port_id)
-                       $hlbgcolor = "bgcolor=".self::HL_PORT_BGCOLOR;
-               else
-                       $hlbgcolor = "bgcolor=$rowbgcolor";
-
-               $link = NULL;
-
-               $port = $this->list[$id];
-
-               $urlparams = array(
-                               'module' => 'redirect',
-                               'page' => 'object',
-                               'tab' => 'linkmgmt',
-                               'op' => 'map',
-                               'usemap' => 1,
-                               'object_id' => $port['object_id'],
-                               );
-
-               if($hl_port_id !== NULL)
-                       $urlparams['hl_port_id'] = $hl_port_id;
-               else
-                       $urlparams['port_id'] = $id;
-
-               $title = "linkcount: ".$this->count." (".$this->front_count."/".$this->back_count.")\nTypeID: ${port['type']}\nPortID: $id";
-
-               $onclick = 'onclick=window.open("'.makeHrefProcess($this->urlparamsarray(
-                                $urlparams)).'","Map","height=500,width=800,scrollbars=yes");';
-
-               /* Current Port */
-               echo '<tr '.$hlbgcolor.'><td nowrap="nowrap" bgcolor='.self::CURRENT_PORT_BGCOLOR.' title="'.$title.
-                       '"><a '.$onclick.'>'.
-                       $this->port['name'].': </a></td>';
-
-               echo "<td><table id=printportlistrow1 align=right><tr><td>";
-
-               $back = empty($this->list[$id]['back']);
-
-               $this->_printportlink(NULL, $id, $link, $back);
-
-               $this->_printportlist($id, !$back);
-               echo "</td></tr></table id=printportlistrow2></td></tr>";
-
-               /* horizontal line */
-                echo '<tr><td height=1 colspan=3 bgcolor=#e0e0e0></td></tr>';
-
-               return true;
-
-       } /* printportlist */
-
-       /*
-        * print <td>
-        * prints all ports in a list starting with start_port_id
-        */
-       /* !!! recursive */
-       function _printportlist($src_port_id, $back = FALSE) {
-
-                if($back)
-                        $linktype = 'back';
-                else
-                        $linktype = 'front';
-
-               if(!empty($this->list[$src_port_id][$linktype])) {
-
-                       $linkcount = count($this->list[$src_port_id][$linktype]);
-
-                       if($linkcount > 1)
-                               echo "<td bgcolor=#f00000></td><td><table id=_printportlist1>";
-
-                       $lastkey = $linkcount - 1;
-
-                       foreach($this->list[$src_port_id][$linktype] as $key => &$link) {
-
-                               if($linkcount > 1) {
-                                       echo "<tr style=\"background-color:".( $key % 2 ? self::ALTERNATE_ROW_BGCOLOR : "#ffffff" )."\"><td><table id=_printportlist2><tr>";
-                               }
-
-                               $dst_port_id = $link['id'];
-
-                               $this->loopcount++;
-
-                               if($this->loopcount > self::MAX_LOOP_COUNT) {
-                               //      $src_port_name = $this->list[$src_port_id]['name'];
-                               //      $dst_port_name = $this->list[$dst_port_id]['name'];
-
-                                       $link['loop'] = $dst_port_id;
-                                       $link['loopmaxcount'] = $dst_port_id;
-
-                                       /* loop warning is handeld in _printportlink() */
-                                       //showWarning("MAX LOOP COUNT reached $src_port_name -> $dst_port_name".self::MAX_LOOP_COUNT);
-                                       //return; /* return after _printportlink */
-                               }
-
-                               if(!$this->_printportlink($src_port_id, $dst_port_id, $link, $back))
-                               {
-                                       return;
-                               }
-
-                               $this->_printportlist($dst_port_id,!$back);
-
-                               if($linkcount > 1) {
-                                       echo "</tr></table></td></tr>"
-                                               .( $key != $lastkey ? "<tr><td height=1 colspan=100% bgcolor=#c0c0c0><td></tr>" : "");
-                               }
-                       }
-
-                       if($linkcount > 1)
-                               echo "</table></td>";
-               }
-       } /* _printportlist */
-
-       /*
-         *  returns linked Row / Rack Info for object_id
-         *
-         */
-        function _getRackInfo($object_id, $style = '') {
-                global $lm_cache;
-
-                $rackinfocache = $lm_cache['rackinfo'];
-
-                /* if not in cache get it */
-                if(!array_key_exists($object_id,$rackinfocache)) {
-
-                                $object = spotEntity('object', $object_id);
-                               $rack_id = $object['rack_id'];
-
-                               if($rack_id)
-                                       $rackinfocache[$object_id] = spotEntity('rack', $object['rack_id']);
-                }
-
-
-                $rack = &$rackinfocache[$object_id];
-
-                if(empty($rack))
-                        return  '<span style="'.$style.'">Unmounted</span>';
-                else
-                        return '<a style="'.$style.'" href='.makeHref(array('page'=>'row', 'row_id'=>$rack['row_id'])).'>'.$rack['row_name']
-                                .'</a>/<a style="'.$style.'" href='.makeHref(array('page'=>'rack', 'rack_id'=>$rack['id'])).'>'
-                                .$rack['name'].'</a>';
-
-        } /* _getRackInfo */
-
-       /*
-        * return link symbol
-        */
-       function _getlinkportsymbol($port_id, $linktype) {
-               $retval = '<span onclick=window.open("'.makeHrefProcess($this->urlparamsarray(
-                       array('op' => 'PortLinkDialog','port' => $port_id,'linktype' => $linktype ))).'","name","height=800,width=800");'
-                       .'>';
-
-                $img = getImageHREF ('plug', $linktype.' Link this port');
-
-               if($linktype == 'back')
-                       $img = str_replace('<img',
-                               '<img style="transform:rotate(180deg);-o-transform:rotate(180deg);-ms-transform:rotate(180deg);-moz-transform:rotate(180deg);-webkit-transform:rotate(180deg);"',
-                               $img);
-
-               $retval .= $img;
-               $retval .= "</span>";
-               return $retval;
-
-       } /* _getlinkportsymbol */
-
-       /*
-        * print link symbol
-        *
-        */
-       function _printlinkportsymbol($port_id, $linktype = 'front') {
-               global $lm_cache;
-
-               if($linktype == 'front' && !$lm_cache['allowlink'])
-                       return;
-
-               if($linktype != 'front' && !$lm_cache['allowbacklink'])
-                       return;
-
-               echo "<td align=center>";
-
-               echo $this->_getlinkportsymbol($port_id, $linktype);
-
-               echo "</td>";
-
-        } /* _printlinkportsymbol */
-
-       /*
-        * return link cut symbol
-        *
-         * TODO $opspec_list
-        */
-       function _printUnLinkPort($src_port_id, &$dst_link, $linktype) {
-               global $lm_cache;
-
-               if($linktype == 'front' && !$lm_cache['allowlink'])
-                       return;
-
-               if($linktype != 'front' && !$lm_cache['allowbacklink'])
-                       return;
-
-               $src_port = $this->list[$src_port_id];
-
-               $dst_port = $this->list[$dst_link['id']];
-
-               /* use RT unlink for front link, linkmgmt unlink for back links */
-               if($linktype == 'back')
-                       $tab = 'linkmgmt';
-               else
-                       $tab = 'ports';
-
-               return '<a href='.
-                               makeHrefProcess(array(
-                                       'op'=>'unlinkPort',
-                                       'port_id'=>$src_port_id,
-                                       'remote_id' => $dst_port['id'],
-                                       'object_id'=>$this->object_id,
-                                       'tab' => $tab,
-                                       'linktype' => $linktype)).
-                       ' onclick="return confirm(\'unlink ports '.$src_port['name']. ' -> '.$dst_port['name']
-                                       .' ('.$linktype.') with cable ID: '.$dst_link['cable'].'?\');">'.
-                       getImageHREF ('cut', $linktype.' Unlink this port').'</a>';
-
-       } /* _printUnLinkPort */
-
-
-       /*
-        *
-         */
-       static function urlparams($name, $value, $defaultvalue = NULL) {
-
-                $urlparams = $_GET;
-
-               if($value == $defaultvalue) {
-
-                       /* remove param */
-                       unset($urlparams[$name]);
-
-               } else {
-
-                       $urlparams[$name] = $value;
-
-               }
-
-                return $urlparams;
-
-        } /* urlparams */
-
-       /*
-         * $params = array('name' => 'value', ...)
-         */
-       static function urlparamsarray($params) {
-
-                $urlparams = $_GET;
-
-               foreach($params as $name => $value) {
-
-                       if($value == NULL) {
-
-                               /* remove param */
-                               unset($urlparams[$name]);
-
-                       } else {
-
-                               $urlparams[$name] = $value;
-
-                       }
-               }
-
-                return $urlparams;
-
-        } /* urlparamsarray */
-
-       /* */
-       static function hasbackend($object_id) {
-               /* sql bitwise xor: porta ^ portb */
-               //select cable, ((porta ^ portb) ^ 4556) as port from Link where (4556 in (porta, portb));
-
-               $result = usePreparedSelectBlade
-               (
-                               'SELECT count(*) from Port
-                                join LinkBackend as LinkBackend_a on LinkBackend_a.porta = id
-                                join LinkBackend as LinkBackend_b on LinkBackend_b.portb = id
-                                where object_id = ?',
-                               array($object_id)
-               );
-               $retval = $result->fetchColumn();
-
-               $result->closeCursor();
-
-               return $retval != 0;
-
-       } /* hasbackend */
-
-       /* for debugging only */
-       function var_dump_html(&$var) {
-               echo "<pre>------------------Start Var Dump -------------------------\n";
-               var_dump($var);
-               echo "\n---------------------END Var Dump ------------------------</pre>";
-       }
-
-} /* portlist */
-
-/* -------------------------------------------------- */
-
 ?>