qls = &$qls; // Gather entitlement data $this->gatherEntitlementData(); if(time() - $this->entitlementArray['lastChecked'] > ENTITLEMENT_CHECK_FREQUENCY) { $this->updateEntitlementData(); $this->gatherEntitlementData(); } // Generate environment tree object $this->envTreeArray = array(); $query = $this->qls->SQL->select('*', 'app_env_tree', false, array('name', 'ASC')); while($row = $this->qls->SQL->fetch_assoc($query)) { $row['name'] = $this->convertHyphens($row['name']); $this->envTreeArray[$row['id']] = $row; } // Add full path names for each environment tree object foreach($this->envTreeArray as &$entry) { $parentID = $entry['parent']; $nameString = $entry['name']; while($parentID != '#') { $nameString = $this->envTreeArray[$parentID]['name'].'.'.$nameString; $parentID = $this->envTreeArray[$parentID]['parent']; } $entry['nameString'] = $nameString; } unset($entry); $this->floorplanObjDetails = array( 'walljack' => array( 'trunkable' => true, 'populatable' => true, 'floorplanConnectable' => true, 'html' => '' ), 'wap' => array( 'trunkable' => true, 'populatable' => true, 'floorplanConnectable' => false, 'html' => '' ), 'device' => array( 'trunkable' => false, 'populatable' => true, 'floorplanConnectable' => false, 'html' => '' ), 'camera' => array( 'trunkable' => true, 'populatable' => true, 'floorplanConnectable' => false, 'html' => '' ) ); $this->templateCategoryArray = array(); $this->templateArray = array(); $query = $this->qls->SQL->select('*', 'app_object_templates'); while($row = $this->qls->SQL->fetch_assoc($query)) { $templateID = $row['id']; $templateType = $row['templateType']; $categoryID = $row['templateCategory_id']; $templateName = $row['templateName']; if(isset($this->floorplanObjDetails[$templateType])) { $this->floorplanObjDetails[$templateType]['templateID'] = $templateID; } if(!isset($this->templateCategoryArray[$categoryID])) { $this->templateCategoryArray[$categoryID] = array(); } $this->templateCategoryArray[$categoryID][$templateName] = array( 'type' => 'regular', 'id' => $templateID ); $this->templateArray[$templateID] = $row; } $this->combinedTemplateArray = array(); $query = $this->qls->SQL->select('*', 'app_combined_templates'); while($row = $this->qls->SQL->fetch_assoc($query)) { $templateID = $row['id']; $categoryID = $row['templateCategory_id']; $templateName = $row['templateName']; if(!isset($this->templateCategoryArray[$categoryID])) { $this->templateCategoryArray[$categoryID] = array(); } $this->templateCategoryArray[$categoryID][$templateName] = array( 'type' => 'combined', 'id' => $templateID ); $this->combinedTemplateArray[$templateID] = $row; } // Sort templates by name foreach($this->templateCategoryArray as &$category) { ksort($category); } // Generate object... object... <.< >.> $this->objectArray = array(); $this->objectByTemplateArray = array(); $this->objectByCabinetArray = array(); $query = $this->qls->SQL->select('*', 'app_object'); while($row = $this->qls->SQL->fetch_assoc($query)) { $row['name'] = $this->convertHyphens($row['name']); $objID = $row['id']; $this->objectArray[$objID] = $row; $templateID = $row['template_id']; if(!isset($this->objectByTemplateArray[$templateID])) { $this->objectByTemplateArray[$templateID] = array(); } array_push($this->objectByTemplateArray[$templateID], $objID); $cabinetID = $row['env_tree_id']; if(!isset($this->objectByCabinetArray[$cabinetID])) { $this->objectByCabinetArray[$cabinetID] = array(); } array_push($this->objectByCabinetArray[$cabinetID], $objID); } //Generate insert object $this->insertArray = array(); $this->insertAddressArray = array(); //$query = $this->qls->SQL->select('*', 'app_object', array('parent_id' => array('<>', 0))); //while($row = $this->qls->SQL->fetch_assoc($query)) { foreach($this->objectArray as $entry) { $parentID = $entry['parent_id']; $parentFace = $entry['parent_face']; $parentDepth = $entry['parent_depth']; $insertSlotX = $entry['insertSlotX']; $insertSlotY = $entry['insertSlotY']; if($parentID > 0) { if(!isset($this->insertArray[$parentID])) { $this->insertArray[$parentID] = array(); } array_push($this->insertArray[$parentID], $entry); $this->insertAddressArray[$parentID][$parentFace][$parentDepth][$insertSlotX][$insertSlotY] = $entry; } } // Add full path names for each object... this is dependant on envTreeArray, templateArray, and objectArray foreach($this->objectArray as &$object) { $nameString = $this->generateObjectName($object['id']); $object['nameString'] = $nameString; } $this->categoryArray = array(); $query = $this->qls->SQL->select('*', 'app_object_category', false, 'name ASC'); while($row = $this->qls->SQL->fetch_assoc($query)) { $this->categoryArray[$row['id']] = $row; } $this->portOrientationArray = array(); $query = $this->qls->SQL->select('*', 'shared_object_portOrientation'); while($row = $this->qls->SQL->fetch_assoc($query)) { $this->portOrientationArray[$row['id']] = $row; } $this->cablePathArray = array(); $query = $this->qls->SQL->select('*', 'app_cable_path'); while($row = $this->qls->SQL->fetch_assoc($query)) { $this->cablePathArray[$row['id']] = $row; } $this->cabinetAdjacencyArray = array(); $this->cabinetAdjacencyArrayFixed = array(); $query = $this->qls->SQL->select('*', 'app_cabinet_adj'); while($row = $this->qls->SQL->fetch_assoc($query)) { $leftCabID = $row['left_cabinet_id']; $rightCabID = $row['right_cabinet_id']; if(!isset($this->cabinetAdjacencyArrayFixed[$leftCabID])) { $this->cabinetAdjacencyArrayFixed[$leftCabID] = array('left' => 0, 'right' => 0); } if(!isset($this->cabinetAdjacencyArrayFixed[$rightCabID])) { $this->cabinetAdjacencyArrayFixed[$rightCabID] = array('left' => 0, 'right' => 0); } $this->cabinetAdjacencyArrayFixed[$leftCabID]['right'] = $rightCabID; $this->cabinetAdjacencyArrayFixed[$rightCabID]['left'] = $leftCabID; $this->cabinetAdjacencyArray[$row['left_cabinet_id']] = $row; $this->cabinetAdjacencyArray[$row['right_cabinet_id']] = $row; } $this->compatibilityArray = array(); $query = $this->qls->SQL->select('*', 'app_object_compatibility'); while($row = $this->qls->SQL->fetch_assoc($query)) { $this->compatibilityArray[$row['template_id']][$row['side']][$row['depth']] = $row; } $this->connectorTypeArray = array(); $this->connectorTypeValueArray = array(); $query = $qls->SQL->select('*', 'shared_cable_connectorType'); while ($row = $qls->SQL->fetch_assoc($query)) { if(strtolower($row['name']) != 'label') { $this->connectorTypeArray[$row['id']] = $row['name']; $this->connectorTypeValueArray[$row['value']] = $row; } } $this->portTypeArray = array(); $this->portTypeValueArray = array(); $query = $qls->SQL->select('*', 'shared_object_portType'); while($row = $qls->SQL->fetch_assoc($query)) { $this->portTypeArray[$row['id']] = $row; $this->portTypeValueArray[$row['value']] = $row; } $this->mediaTypeArray = array(); $this->mediaTypeByIDArray = array(); $query = $qls->SQL->select('*', 'shared_mediaType', array('display' => array('=', 1))); while($row = $qls->SQL->fetch_assoc($query)) { array_push($this->mediaTypeArray, $row); $this->mediaTypeByIDArray[$row['value']] = $row; } $this->mediaTypeValueArray = array(); $query = $qls->SQL->select('*', 'shared_mediaType'); while($row = $qls->SQL->fetch_assoc($query)) { $this->mediaTypeValueArray[$row['value']] = $row; } $this->mediaCategoryTypeArray = array(); $query = $qls->SQL->select('*', 'shared_mediaCategoryType'); while($row = $qls->SQL->fetch_assoc($query)) { $this->mediaCategoryTypeArray[$row['value']] = $row; } $this->inventoryArray = array(); $this->inventoryAllArray = array(); $this->inventoryByIDArray = array(); $query = $this->qls->SQL->select('*', 'app_inventory'); while($row = $this->qls->SQL->fetch_assoc($query)) { $this->inventoryAllArray[$row['id']] = $row; if($row['a_object_id'] != 0) { if(!isset($this->inventoryArray[$row['a_object_id']][$row['a_object_face']][$row['a_object_depth']][$row['a_port_id']])) { $this->inventoryArray[$row['a_object_id']][$row['a_object_face']][$row['a_object_depth']][$row['a_port_id']] = array(); } array_push($this->inventoryArray[$row['a_object_id']][$row['a_object_face']][$row['a_object_depth']][$row['a_port_id']], array( 'rowID' => $row['id'], 'id' => $row['b_object_id'], 'face' => $row['b_object_face'], 'depth' => $row['b_object_depth'], 'port' => $row['b_port_id'], 'localEndID' => $row['a_id'], 'localAttrPrefix' => 'a', 'remoteEndID' => $row['b_id'], 'remoteAttrPrefix' => 'b' )); } if($row['b_object_id'] != 0) { if(!isset($this->inventoryArray[$row['b_object_id']][$row['b_object_face']][$row['b_object_depth']][$row['b_port_id']])) { $this->inventoryArray[$row['b_object_id']][$row['b_object_face']][$row['b_object_depth']][$row['b_port_id']] = array(); } array_push($this->inventoryArray[$row['b_object_id']][$row['b_object_face']][$row['b_object_depth']][$row['b_port_id']], array( 'rowID' => $row['id'], 'id' => $row['a_object_id'], 'face' => $row['a_object_face'], 'depth' => $row['a_object_depth'], 'port' => $row['a_port_id'], 'localEndID' => $row['b_id'], 'localAttrPrefix' => 'b', 'remoteEndID' => $row['a_id'], 'remoteAttrPrefix' => 'a' )); } if($row['a_id'] != 0) { $this->inventoryByIDArray[$row['a_id']] = array( 'rowID' => $row['id'], 'local_object_id' => $row['a_object_id'], 'local_object_face' => $row['a_object_face'], 'local_object_depth' => $row['a_object_depth'], 'local_object_port' => $row['a_port_id'], 'remote_object_id' => $row['b_object_id'], 'remote_object_face' => $row['b_object_face'], 'remote_object_depth' => $row['b_object_depth'], 'remote_object_port' => $row['b_port_id'], 'localEndID' => $row['a_id'], 'localEndCode39' => $row['a_code39'], 'localConnector' => $row['a_connector'], 'localAttrPrefix' => 'a', 'remoteEndID' => $row['b_id'], 'remoteEndCode39' => $row['b_code39'], 'remoteConnector' => $row['b_connector'], 'remoteAttrPrefix' => 'b', 'mediaType' => $row['mediaType'], 'length' => $row['length'], 'editable' => $row['editable'] ); } if($row['b_id'] != 0) { $this->inventoryByIDArray[$row['b_id']] = array( 'rowID' => $row['id'], 'local_object_id' => $row['b_object_id'], 'local_object_face' => $row['b_object_face'], 'local_object_depth' => $row['b_object_depth'], 'local_object_port' => $row['b_port_id'], 'remote_object_id' => $row['a_object_id'], 'remote_object_face' => $row['a_object_face'], 'remote_object_depth' => $row['a_object_depth'], 'remote_object_port' => $row['a_port_id'], 'localEndID' => $row['b_id'], 'localEndCode39' => $row['b_code39'], 'localConnector' => $row['b_connector'], 'localAttrPrefix' => 'b', 'remoteEndID' => $row['a_id'], 'remoteEndCode39' => $row['a_code39'], 'remoteConnector' => $row['a_connector'], 'remoteAttrPrefix' => 'a', 'mediaType' => $row['mediaType'], 'length' => $row['length'], 'editable' => $row['editable'] ); } } $this->populatedPortArray = array(); $this->populatedPortAllArray = array(); $query = $this->qls->SQL->select('*', 'app_populated_port'); while ($row = $this->qls->SQL->fetch_assoc($query)){ array_push($this->populatedPortAllArray, $row); $this->populatedPortArray[$row['object_id']][$row['object_face']][$row['object_depth']][$row['port_id']] = array( 'rowID' => $row['id'] ); } $this->peerArrayStandard = array(); $this->peerArray = array(); $this->peerArrayStandardFloorplan = array(); $this->peerArrayWalljack = array(); $this->peerArrayWalljackEntry = array(); $query = $this->qls->SQL->select('*', 'app_object_peer'); while($row = $this->qls->SQL->fetch_assoc($query)) { $rowID = $row['id']; // ObjectA Data $aID = $row['a_id']; $aFace = $row['a_face']; $aDepth = $row['a_depth']; $aPort = $row['a_port']; $aEndpoint = $row['a_endpoint']; // ObjectB Data $bID = $row['b_id']; $bFace = $row['b_face']; $bDepth = $row['b_depth']; $bPort = $row['b_port']; $bEndpoint = $row['b_endpoint']; if(!isset($this->peerArray[$aID][$aFace][$aDepth])) { $this->peerArray[$aID][$aFace][$aDepth] = array( 'id' => $rowID, 'selfPort' => $aPort, 'selfEndpoint' => $aEndpoint, 'peerID' => $bID, 'peerFace' => $bFace, 'peerDepth' => $bDepth, 'peerEndpoint' => $bEndpoint, 'floorplanPeer' => $row['floorplan_peer'] ); } if($row['floorplan_peer']) { if(!isset($this->peerArray[$aID][$aFace][$aDepth]['peerArray'][$bID][$bFace][$bDepth])) { $this->peerArray[$aID][$aFace][$aDepth]['peerArray'][$bID][$bFace][$bDepth] = array(); } $this->peerArray[$aID][$aFace][$aDepth]['peerArray'][$bID][$bFace][$bDepth][$rowID] = array((int)$aPort, (int)$bPort); } if(!isset($this->peerArray[$bID][$bFace][$bDepth])) { $this->peerArray[$bID][$bFace][$bDepth] = array( 'id' => $rowID, 'selfPort' => $bPort, 'selfEndpoint' => $bEndpoint, 'peerID' => $aID, 'peerFace' => $aFace, 'peerDepth' => $aDepth, 'peerEndpoint' => $aEndpoint, 'floorplanPeer' => $row['floorplan_peer'] ); } if($row['floorplan_peer']) { if(!isset($this->peerArray[$bID][$bFace][$bDepth]['peerArray'][$aID][$aFace][$aDepth])) { $this->peerArray[$bID][$bFace][$bDepth]['peerArray'][$aID][$aFace][$aDepth] = array(); } $this->peerArray[$bID][$bFace][$bDepth]['peerArray'][$aID][$aFace][$aDepth][$rowID] = array((int)$bPort, (int)$aPort); } if(!$row['floorplan_peer']) { $this->peerArrayStandard[$aID][$aFace][$aDepth] = array( 'rowID' => $rowID, 'selfEndpoint' => $aEndpoint, 'id' => $bID, 'face' => $bFace, 'depth' => $bDepth, 'port' => false, 'endpoint' => $bEndpoint, 'floorplanPeer' => $row['floorplan_peer'] ); $this->peerArrayStandard[$bID][$bFace][$bDepth] = array( 'rowID' => $rowID, 'selfEndpoint' => $bEndpoint, 'id' => $aID, 'face' => $aFace, 'depth' => $aDepth, 'port' => false, 'endpoint' => $aEndpoint, 'floorplanPeer' => $row['floorplan_peer'] ); } else { if(!isset($this->peerArrayWalljack[$aID])) { $this->peerArrayWalljack[$aID] = array(); } array_push($this->peerArrayWalljack[$aID], array( 'rowID' => $rowID, 'selfID' => $aID, 'selfPortID' => $aPort, 'id' => $bID, 'face' => $bFace, 'depth' => $bDepth, 'port' => $bPort, 'endpoint' => $bEndpoint, 'floorplanPeer' => $row['floorplan_peer'] )); $this->peerArrayWalljackEntry[$aID][$aFace][$aDepth][$aPort] = array( 'rowID' => $rowID, 'id' => $bID, 'face' => $bFace, 'depth' => $bDepth, 'port' => $bPort, 'endpoint' => $bEndpoint, 'floorplanPeer' => $row['floorplan_peer'] ); $this->peerArrayStandardFloorplan[$bID][$bFace][$bDepth][$bPort] = array( 'rowID' => $rowID, 'id' => $aID, 'face' => $aFace, 'depth' => $aDepth, 'port' => $aPort, 'endpoint' => $aEndpoint, 'floorplanPeer' => $row['floorplan_peer'] ); } } // History Action Type $this->historyActionTypeArray = array(); $query = $qls->SQL->select('*', 'shared_history_action_type'); while($row = $qls->SQL->fetch_assoc($query)) { $this->historyActionTypeArray[$row['value']] = $row; } // History Function $this->historyFunctionArray = array(); $query = $qls->SQL->select('*', 'shared_history_function'); while($row = $qls->SQL->fetch_assoc($query)) { $this->historyFunctionArray[$row['value']] = $row; } } function generateObjectPortName($objID, $objFace, $objDepth, $objPort) { if($objID == 0) { $objectPortName = 'None'; } else { $obj = $this->objectArray[$objID]; $objName = $obj['nameString']; $objTemplateID = $obj['template_id']; $objTemplate = $this->templateArray[$objTemplateID]; $objCompatibility = $this->compatibilityArray[$objTemplateID][$objFace][$objDepth]; $objTemplateType = $objTemplate['templateType']; $objTemplateFunction = $objCompatibility['partitionFunction']; if($objTemplateType == 'walljack') { if(isset($this->peerArray[$objID][$objFace][$objDepth]['peerArray'])) { $peerData = $this->peerArray[$objID][$objFace][$objDepth]['peerArray']; foreach($peerData as $peerID => $peer) { $peerObj = $this->objectArray[$peerID]; $peerTemplateID = $peerObj['template_id']; foreach($peer as $peerFace => $partition) { foreach($partition as $peerDepth => $portPair) { foreach($portPair as $port) { if($port[0] == $objPort) { $peerCompatibility = $this->compatibilityArray[$peerTemplateID][$peerFace][$peerDepth]; $peerPortNameFormat = json_decode($peerCompatibility['portNameFormat'], true); $peerPortTotal = $peerCompatibility['portTotal']; $peerPortID = $port[1]; $peerPortName = $this->generatePortName($peerPortNameFormat, $peerPortID, $peerPortTotal); $objPortNameArray = array($objName, $peerPortName); $objectPortName = implode('.', $objPortNameArray); //$objectPortName = $objectPortName.'('.$objPort.')'; } } } } } } } else { $portNameFormat = json_decode($objCompatibility['portNameFormat'], true); $portTotal = $objCompatibility['portTotal']; $objPortName = $this->generatePortName($portNameFormat, $objPort, $portTotal); if($objTemplateType == 'Insert' and $objTemplateFunction == 'Endpoint') { $objectPortName = $objName.$objPortName; } else { $objPortNameArray = array($objName, $objPortName); $objectPortName = implode('.', $objPortNameArray); } } } return $objectPortName; } function generateObjectName($objID, $includeTree=true, $includeInsertParentName=true) { $object = $this->objectArray[$objID]; $envTreeID = $object['env_tree_id']; $objectTemplateID = $object['template_id']; $template = $this->templateArray[$objectTemplateID]; $templateType = $template['templateType']; $templateFunction = $template['templateFunction']; $locationArray = array(); // Save object name separately if it's an insert if($templateType == 'Insert') { $objName = $object['name']; $parentID = $object['parent_id']; $object = $this->objectArray[$parentID]; $objectTemplateID = $object['template_id']; $template = $this->templateArray[$objectTemplateID]; $templateType = $template['templateType']; if($templateType == 'Insert') { $templateFunction = $template['templateFunction']; $separator = ($templateFunction == 'Endpoint') ? '' : '.'; $objName = $object['name'].$separator.$objName; $parentID = $object['parent_id']; $object = $this->objectArray[$parentID]; } array_unshift($locationArray, $objName); } if($includeInsertParentName) { array_unshift($locationArray, $object['name']); } if($includeTree) { //Locations $rootTreeNode = false; while(!$rootTreeNode) { if(isset($this->envTreeArray[$envTreeID])) { $node = $this->envTreeArray[$envTreeID]; $nodeName = $node['name']; array_unshift($locationArray, $nodeName); $envTreeID = $node['parent']; $rootTreeNode = $envTreeID == '#' ? true : false; } else { $rootTreeNode = true; } } } return implode('.', $locationArray); } /** * Generates human readable port name * @return string */ function generatePortName($portNameFormat, $index, $portTotal) { $portString = ''; $incrementalCount = 0; // Create character arrays $lowercaseIncrementArray = array(); $uppercaseIncrementArray = array(); for($x=97; $x<=122; $x++) { array_push($lowercaseIncrementArray, chr($x)); } for($x=65; $x<=90; $x++) { array_push($uppercaseIncrementArray, chr($x)); } // Account for infinite count incrementals foreach($portNameFormat as &$itemA) { $type = $itemA['type']; if($type == 'incremental' or $type == 'series') { $incrementalCount++; if($itemA['count'] == 0) { $itemA['count'] = $portTotal; } } } foreach($portNameFormat as $itemB) { $type = $itemB['type']; $value = $itemB['value']; $order = $itemB['order']; $count = $itemB['count']; if($type == 'static') { $portString = $portString.$value; } else if($type == 'incremental' or $type == 'series') { $numerator = 1; if($order < $incrementalCount) { foreach($portNameFormat as $itemC) { $typeC = $itemC['type']; $orderC = $itemC['order']; $countC = $itemC['count']; if($typeC == 'incremental' or $typeC == 'series') { if($order < $orderC) { $numerator *= $countC; } } } } $howMuchToIncrement = floor($index / $numerator); if($howMuchToIncrement >= $count) { $rollOver = floor($howMuchToIncrement / $count); $howMuchToIncrement = $howMuchToIncrement - ($rollOver * $count); } if($type == 'incremental') { if(is_numeric($value)) { $value = $value + $howMuchToIncrement; $portString = $portString.$value; } else { $asciiValue = ord($value); $asciiIndex = $asciiValue + $howMuchToIncrement; if($asciiValue >= 65 && $asciiValue <= 90) { // Uppercase while($asciiIndex > 90) { $portString = $portString.$uppercaseIncrementArray[0]; $asciiIndex -= 26; } $portString = $portString.$uppercaseIncrementArray[$asciiIndex-65]; } else if($asciiValue >= 97 && $asciiValue <= 122) { // Lowercase while($asciiIndex > 122) { $portString = $portString.$lowercaseIncrementArray[0]; $asciiIndex -= 26; } $portString = $portString.$lowercaseIncrementArray[$asciiIndex-97]; } } } else if($type == 'series') { $portString = $portString.$value[$howMuchToIncrement]; } } } return $portString; } /** * Generates unique object name * @return string */ function findUniqueName($parentID, $nameType, $name=false){ for($count=0; $count<10; $count++) { $uniqueNameValue = $this->generateUniqueNameValue(); // Search for duplicate name if($nameType == 'object') { $uniqueName = NEW_OBJECT_PREFIX.$uniqueNameValue; $query = $this->qls->SQL->select('*', 'app_object', array('env_tree_id' => array('=', $parentID), 'AND', 'name' => array('=', $uniqueName))); } else if($nameType == 'template') { $uniqueName = $name.'_'.$uniqueNameValue; $query = $this->qls->SQL->select('*', 'app_object_templates', array('templateName' => array('=', $uniqueName))); } else { if($nameType == 'location') { $uniqueName = NEW_LOCATION_PREFIX.$uniqueNameValue; } else if($nameType == 'pod') { $uniqueName = NEW_POD_PREFIX.$uniqueNameValue; } else if($nameType == 'cabinet') { $uniqueName = NEW_CABINET_PREFIX.$uniqueNameValue; } else if($nameType == 'floorplan') { $uniqueName = NEW_FLOORPLAN_PREFIX.$uniqueNameValue; } else { return false; } $query = $this->qls->SQL->select('*', 'app_env_tree', array('parent' => array('=', $parentID), 'AND', 'name' => array('=', $uniqueName))); } if(!$this->qls->SQL->num_rows($query)) { return $uniqueName; } } return false; } /** * Generates unique name value * @return string */ function generateUniqueNameValue(){ $characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'; $length = 4; $charactersLength = strlen($characters); $uniqueNameValue = ''; for($i = 0; $i < $length; $i++) { $uniqueNameValue .= $characters[rand(0, $charactersLength - 1)]; } return $uniqueNameValue; } /** * Builds information about an object * @return array */ function getObject($objID, $portID=0, $objFace=0, $objDepth=0, $incPortName=true){ $return = array( 'obj' => array(), 'function' => '', 'id' => $objID, 'selected' => false, 'nameString' => '' ); //Build the object if(isset($this->objectArray[$objID])) { $obj = $this->objectArray[$objID]; } else { $return['id'] = 0; return $return; } $templateID = $obj['template_id']; $categoryID = $this->templateArray[$templateID]['templateCategory_id']; $return['categoryID'] = $categoryID; $objCompatibility = $this->compatibilityArray[$templateID][$objFace][$objDepth]; $templateType = $objCompatibility['templateType']; // Retrieve port info if($incPortName) { if($templateType == 'walljack') { $peerEntry = $this->peerArrayWalljackEntry[$objID][$objFace][$objDepth][$portID]; $portID = $peerEntry['port']; $peerObj = $this->objectArray[$peerEntry['id']]; $peerTemplateID = $peerObj['template_id']; $objCompatibility = $this->compatibilityArray[$peerTemplateID][$peerEntry['face']][$peerEntry['depth']]; } else if($templateType == 'wap' or $templateType == 'device'){ $portName = 'NIC1'; } $return['function'] = $objCompatibility['partitionFunction']; $portNameFormat = json_decode($objCompatibility['portNameFormat'], true); $portTotal = $objCompatibility['portLayoutX']*$objCompatibility['portLayoutY']; $portName = $this->generatePortName($portNameFormat, $portID, $portTotal); $templateType = $objCompatibility['templateType']; if($templateType == 'Insert') { $separator = $return['function'] == 'Passive' ? '.' : ''; $portName = $obj['name'] == '' ? $portName : $obj['name'].$separator.$portName; } array_unshift($return['obj'], $portName); } if($templateType == 'Insert') { $query = $this->qls->SQL->select('*', 'app_object', array('id' => array('=', $obj['parent_id']))); $obj = $this->qls->SQL->fetch_assoc($query); } $side = ''; if($this->templateArrray[$obj['template_id']]['templateMountConfig'] == 1){ $side = $objFace == 0 ? '(front)' : '(back)'; } array_unshift($return['obj'], $obj['name']); $objParentID = $obj['env_tree_id']; while($objParentID != '#'){ $obj = $this->envTreeArray[$objParentID]; array_unshift($return['obj'], $obj['name']); $objParentID = $obj['parent']; } $return['nameString'] = implode('.', $return['obj']); return $return; } function getPortNameString($objID, $objFace, $objDepth, $portID){ $nameArray = array(); $objectArray = $this->objectArray; $compatibilityArray = $this->compatibilityArray; $templateArray = $this->templateArray; $envTreeArray = $this->envTreeArray; $peerArrayWalljackEntry = $this->peerArrayWalljackEntry; $obj = $objectArray[$objID]; $templateID = $obj['template_id']; $objCompatibility = $compatibilityArray[$templateID][$objFace][$objDepth]; $template = $this->templateArray[$templateID]; $templateType = $template['templateType']; if($templateType == 'walljack') { $peerEntry = $peerArrayWalljackEntry[$objID][$objFace][$objDepth][$portID]; $portID = $peerEntry['port']; $peerObj = $objectArray[$peerEntry['id']]; $peerTemplateID = $peerObj['template_id']; $objCompatibility = $compatibilityArray[$peerTemplateID][$peerEntry['face']][$peerEntry['depth']]; $template = $this->templateArray[$peerTemplateID]; $templateType = $template['templateType']; } $return['function'] = $objCompatibility['partitionFunction']; $portNameFormat = json_decode($objCompatibility['portNameFormat'], true); $portTotal = $objCompatibility['portLayoutX']*$objCompatibility['portLayoutY']; $portName = $this->generatePortName($portNameFormat, $portID, $portTotal); if($templateType == 'Insert') { $objParentID = $obj['parent_id']; $separator = ($return['function'] == 'Passive') ? '.' : ''; $nestedParentHUnits = $template['nestedParentHUnits']; $nestedParentVUnits = $template['nestedParentVUnits']; if(isset($nestedParentHUnits) and isset($nestedParentVUnits)) { $objParent = $this->objectArray[$objParentID]; $objName = $objParent['name'].$separator.$obj['name']; $objParentID = $objParent['parent_id']; } else { $objName = $objName; } $portName = ($obj['name'] == '') ? $portName : $objName.$separator.$portName; $obj = $objectArray[$objParentID]; } array_unshift($nameArray, $portName); $side = ''; if($templateArray[$obj['template_id']]['templateMountConfig'] == 1){ $side = $objFace == 0 ? '(front)' : '(back)'; } array_unshift($nameArray, $obj['name']); $objParentID = $obj['env_tree_id']; while($objParentID != '#'){ $obj = $envTreeArray[$objParentID]; array_unshift($nameArray, $obj['name']); $objParentID = $obj['parent']; } foreach($nameArray as $index => $element) { if($index < (count($nameArray)-1)) { $portNameString .= $element.'.'; } else { $portNameString .= $element; } } return $portNameString; } /** * Find object peer * @return array */ function findPeer($objID, $objFace, $objDepth, $objPort){ $obj = $this->objectArray[$objID]; $objTemplate = $this->templateArray[$obj['template_id']]; // Find peer or return if nothing found if($objTemplate['templateType'] == 'walljack' or $objTemplate['templateType'] == 'wap') { return $this->peerArrayWalljackEntry[$objID][$objFace][$objDepth][$objPort]; } else { if(isset($this->peerArrayStandard[$objID][$objFace][$objDepth])) { $peer = $this->peerArrayStandard[$objID][$objFace][$objDepth]; } else if(isset($this->peerArrayStandardFloorplan[$objID][$objFace][$objDepth][$objPort])) { $peer = $this->peerArrayStandardFloorplan[$objID][$objFace][$objDepth][$objPort]; } return $peer; } } function retrievePorts($objID, $objFace, $objDepth, $objPort) { $obj = $this->objectArray[$objID]; $templateID = $obj['template_id']; $template = $this->templateArray[$templateID]; $objType = $template['templateType']; $portOptions = ''; if($objType == 'walljack') { foreach($this->peerArrayWalljack[$objID] as $peerEntry) { $peerID = $peerEntry['id']; $peerFace = $peerEntry['face']; $peerDepth = $peerEntry['depth']; $peerPortID = $peerEntry['port']; $selfPortID = $peerEntry['selfPortID']; $walljackPortID = $peerEntry['selfPortID']; $peerObj = $this->objectArray[$peerID]; $peerTemplateID = $peerObj['template_id']; $peerTemplate = $this->templateArray[$peerTemplateID]; $objType = $peerTemplate['templateType']; $objCompatibility = $this->compatibilityArray[$peerTemplateID][$peerFace][$peerDepth]; $partitionFunction = $objCompatibility['partitionFunction']; $portNameFormat = json_decode($objCompatibility['portNameFormat'], true); $portTotal = $objCompatibility['portLayoutX']*$objCompatibility['portLayoutY']; $objName = $peerObj['name']; // Nested insert object name if($objType == 'Insert') { $nestedParentHUnits = $template['nestedParentHUnits']; $nestedParentVUnits = $template['nestedParentVUnits']; if(isset($nestedParentHUnits) and isset($nestedParentVUnits)) { $parentObjID = $obj['parent_id']; $parentObj = $this->objectArray[$parentObjID]; $parentObjName = $parentObj['name']; $objName = ($partitionFunction == 'Endpoint') ? $parentObjName.$objName : $parentObjName.'.'.$objName; } } $portFlags = $this->getPortFlags($objID, $objFace, $objDepth, $selfPortID); $selected = $walljackPortID == $objPort ? ' selected' : ''; $portName = $this->generatePortName($portNameFormat, $peerPortID, $portTotal); $portString = ($objType == 'Insert' and $partitionFunction == 'Endpoint') ? $objName.$portName : $portName; $portOptions .= ''; } } else { $objCompatibility = $this->compatibilityArray[$templateID][$objFace][$objDepth]; $partitionFunction = $objCompatibility['partitionFunction']; $portNameFormat = json_decode($objCompatibility['portNameFormat'], true); $portTotal = $objCompatibility['portLayoutX']*$objCompatibility['portLayoutY']; $objName = $obj['name']; $separator = ($partitionFunction == 'Endpoint') ? '' : '.'; // Nested insert object name if($objType == 'Insert') { $nestedParentHUnits = $template['nestedParentHUnits']; $nestedParentVUnits = $template['nestedParentVUnits']; if(isset($nestedParentHUnits) and isset($nestedParentVUnits)) { $parentObjID = $obj['parent_id']; $parentObj = $this->objectArray[$parentObjID]; $parentObjName = $parentObj['name']; $objName = $parentObjName.$separator.$objName; } } for($x=0; $x<$portTotal; $x++) { $portFlags = $this->getPortFlags($objID, $objFace, $objDepth, $x); $selected = $x == $objPort ? ' selected' : ''; $portName = $this->generatePortName($portNameFormat, $x, $portTotal); $portString = ($objType == 'Insert') ? $objName.$separator.$portName : $portName; $portOptions .= ''; } } return $portOptions; } function buildTreePathString($nodeID){ $node = $this->envTreeArray[$nodeID]; $nodeName = $node['name']; $nodeParentID = $node['parent']; $treePathArray = array($nodeName); while($nodeParentID != '#') { $node = $this->envTreeArray[$nodeParentID]; $nodeName = $node['name']; $nodeParentID = $node['parent']; array_unshift($treePathArray, $nodeName); } $treePath = implode('.', $treePathArray); return $treePath; } function buildTreeLocation(){ $treeArray = array(); $treeSort = $this->qls->user_info['treeSort']; $treeSortAdj = $this->qls->user_info['treeSortAdj']; $counter = 1; $visitedNodeArray = array(); if($treeSort == 0) { $query = $this->qls->SQL->select('*', 'app_env_tree', false, array('name', 'ASC')); } else if($treeSort == 1) { $query = $this->qls->SQL->select('*', 'app_env_tree', false, array('order', 'ASC')); } while($envNode = $this->qls->SQL->fetch_assoc($query)) { $nodeID = $envNode['id']; $nodeName = $envNode['name']; $nodeParent = $envNode['parent']; $nodeType = $envNode['type']; if($nodeType == 'location' || $nodeType == 'pod') { $elementType = 0; } else if($nodeType == 'cabinet' || $nodeType == 'floorplan') { $elementType = 1; } $value = array($elementType, $nodeID, 0, 0, 0); $value = implode('-', $value); $nodeEntry = array( 'id' => $nodeID, 'order' => $counter, 'text' => $nodeName, 'parent' => $nodeParent, 'type' => $nodeType, 'data' => array('globalID' => $value) ); if($treeSortAdj == 1) { // Does node have adjacency? if(isset($this->cabinetAdjacencyArrayFixed[$nodeID]) and !in_array($nodeID, $visitedNodeArray)) { $adjNodeID = $nodeID; // Find the left most cabinet while($this->cabinetAdjacencyArrayFixed[$adjNodeID]['left'] != 0) { $adjNodeID = $this->cabinetAdjacencyArrayFixed[$adjNodeID]['left']; } // Add adjacent cabinet series in order while($adjNodeID != 0) { $left = $this->cabinetAdjacencyArrayFixed[$adjNodeID]['left']; $right = $this->cabinetAdjacencyArrayFixed[$adjNodeID]['right']; if($left == 0 and $right != 0) { $adjIndicator = '↓'; } else if($left != 0 and $right != 0) { $adjIndicator = '↕'; } else if($left != 0 and $right == 0) { $adjIndicator = '↑'; } else { $adjIndicator = ''; } $node = $this->envTreeArray[$adjNodeID]; $nodeName = $adjIndicator.$node['name']; $nodeParent = $node['parent']; $nodeType = $node['type']; if($nodeType == 'location' || $nodeType == 'pod') { $elementType = 0; } else if($nodeType == 'cabinet' || $nodeType == 'floorplan') { $elementType = 1; } $value = array($elementType, $adjNodeID, 0, 0, 0); $value = implode('-', $value); $nodeEntry = array( 'id' => $adjNodeID, 'order' => $counter, 'text' => $nodeName, 'parent' => $nodeParent, 'type' => $nodeType, 'data' => array('globalID' => $value) ); // Add node $treeArray[] = $nodeEntry; $counter++; array_push($visitedNodeArray, $adjNodeID); $adjNodeID = $this->cabinetAdjacencyArrayFixed[$adjNodeID]['right']; } } else { if(!in_array($nodeID, $visitedNodeArray)) { // Add node $treeArray[] = $nodeEntry; $counter++; array_push($visitedNodeArray, $nodeID); } } } else { // Add node $treeArray[] = $nodeEntry; $counter++; } } return $treeArray; } function buildTreeObjects($cabinetID){ $treeArray = array(); $objSort = $this->qls->user_info['objSort']; if($objSort == 0) { // Sort objects by name $objSortAttr = 'name'; $objSortDir = 'ASC'; } else { // Sort objects by RU $objSortAttr = 'RU'; $cabinet = $this->envTreeArray[$cabinetID]; $cabinetRUOrientation = $cabinet['ru_orientation']; if($cabinetRUOrientation == 0) { $objSortDir = 'DESC'; } else { $objSortDir = 'ASC'; } } $query = $this->qls->SQL->select('*', 'app_object', array('env_tree_id' => array('=', $cabinetID), 'AND', 'parent_id' => array('=', 0)), array($objSortAttr, $objSortDir)); $counter = 1; while($objectNode = $this->qls->SQL->fetch_assoc($query)) { if($objectNode['env_tree_id'] == $cabinetID and $objectNode['parent_id'] == 0) { $objectID = $objectNode['id']; $objectName = $objectNode['name']; $objectTemplateID = $objectNode['template_id']; $objectTemplate = $this->templateArray[$objectTemplateID]; $objectType = $objectTemplate['templateType']; $value = array(2, $objectID, 0, 0, 0); $value = implode('-', $value); array_push($treeArray, array( 'id' => 'O'.$objectID, 'order' => $counter, 'text' => $objectName, 'parent' => $cabinetID, 'type' => 'object', 'objectType' => $objectType, 'data' => array('globalID' => $value, 'objectID' => $objectID) )); } $counter++; } return $treeArray; } function buildTreePorts($nodeID, $objectCompatibility, $cablePortType, $cableMediaType, $forTrunk=false){ $treeArray = array(); $element = $this->objectArray[$nodeID]; $templateID = $element['template_id']; $template = $this->templateArray[$templateID]; $templateFunction = $template['templateFunction']; $elementArray = array(); if(($forTrunk and $templateFunction != 'Endpoint') or !$forTrunk) { // Iterate over selected object partitions if(isset($this->compatibilityArray[$templateID])) { foreach($this->compatibilityArray[$templateID] as $nodeFace => $nodeFaceObj) { foreach($nodeFaceObj as $nodeDepth => $partition) { $partitionType = $partition['partitionType']; $partitionFunction = $partition['partitionFunction']; $templateType = $partition['templateType']; if($partitionType == 'Enclosure') { // Iterate over enclosure inserts if(isset($this->insertAddressArray[$nodeID][$nodeFace][$nodeDepth])) { foreach($this->insertAddressArray[$nodeID][$nodeFace][$nodeDepth] as $slotX => $encRow) { foreach($encRow as $slotY => $insert) { $insertID = $insert['id']; $insertName = $insert['name']; $insertTemplateID = $insert['template_id']; if(isset($this->compatibilityArray[$insertTemplateID])) { foreach($this->compatibilityArray[$insertTemplateID] as $insertFace => $insertFaceObj) { foreach($insertFaceObj as $insertDepth => $insertPartition) { // Cannot be a trunked endpoint if(!$this->peerArrayStandard[$insertID][0][$insertDepth]['selfEndpoint']) { $separator = $insertPartition['partitionFunction'] == 'Endpoint' ? '' : '.'; $insertPartition['objectID'] = $insertID; $insertPartition['portNamePrefix'] = $insertName == '' ? '' : $insertName.$separator; array_push($elementArray, $insertPartition); } } } } } } } } else if($templateType == 'Insert') { // Cannot be a trunked endpoint if(!$this->peerArrayStandard[$nodeID][$nodeFace][$nodeDepth]['selfEndpoint']) { $separator = $partitionFunction == 'Endpoint' ? '' : '.'; $rowPartitionElement = $partition; $rowPartitionElement['objectID'] = $nodeID; $rowPartitionElement['portNamePrefix'] = $element['name'] == '' ? '' : $element['name'].$separator; array_push($elementArray, $rowPartitionElement); } } else { // Cannot be a trunked endpoint if(!$this->peerArrayStandard[$nodeID][$nodeFace][$nodeDepth]['selfEndpoint']) { $rowPartitionElement = $partition; $rowPartitionElement['objectID'] = $nodeID; $rowPartitionElement['portNamePrefix'] = ''; array_push($elementArray, $rowPartitionElement); } } } } } } foreach($elementArray as $elementItem) { $elementPortType = $elementItem['portType']; $elementMediaCategory = $elementItem['mediaCategory']; $elementMediaCategoryType = $elementItem['mediaCategoryType']; $elementPartitionFunction = $elementItem['partitionFunction']; if($cablePortType) { $cableMediaCategory = $this->mediaTypeByIDArray[$cableMediaType]['category_id']; // Media category must be compatible (Copper, Singlmode, Multimode) if($elementMediaCategory == $cableMediaCategory and $elementPortType == $cablePortType) { $isCompatible = true; } else if($elementPartitionFunction == 'Endpoint' and $elementPortType == $cablePortType) { $isCompatible = true; } else if($elementPortType == 4) { $isCompatible = true; } else { $isCompatible = false; } } else if($objectCompatibility) { $objectMediaCategory = $objectCompatibility['mediaCategory']; $objectMediaCategoryType = $objectCompatibility['mediaCategoryType']; $objectPortType = $objectCompatibility['portType']; $objectPartitionFunction = $objectCompatibility['partitionFunction']; // Media category must be compatible (Copper, Singlmode, Multimode) if($elementMediaCategory == $objectMediaCategory) { $isCompatible = true; // Port type must be compatible } else if($elementMediaCategoryType == $objectMediaCategoryType and ($elementPartitionFunction == 'Endpoint' or $objectPartitionFunction == 'Endpoint')) { $isCompatible = true; // If either port type is SFP, then they are compatible } else if($elementPortType == 4 or $objectPortType == 4) { $isCompatible = true; // Failing all of that, not compatible } else { $isCompatible = false; } } if($forTrunk and isset($this->peerArrayStandard[$nodeID][$elementItem['side']][$elementItem['depth']])) { $isCompatible = false; } if($isCompatible) { if($elementItem['templateType'] == 'walljack') { if(isset($this->peerArrayWalljack[$nodeID])) { foreach($this->peerArrayWalljack[$nodeID] as $peerEntry) { $peerID = $peerEntry['id']; $peerFace = $peerEntry['face']; $peerDepth = $peerEntry['depth']; $peerPort = $peerEntry['port']; $selfPortID = $peerEntry['selfPortID']; $peerObject = $this->objectArray[$peerID]; $peerTemplateID = $peerObject['template_id']; $peerCompatibility = $this->compatibilityArray[$peerTemplateID][$peerFace][$peerDepth]; $portTotal = $peerCompatibility['portLayoutX'] * $peerCompatibility['portLayoutY']; $portNameFormat = json_decode($peerCompatibility['portNameFormat'], true); $flagString = $this->getPortFlags($nodeID, 0, 0, $selfPortID); $portName = $this->generatePortName($portNameFormat, $peerPort, $portTotal); $portName = $portName.$flagString; $value = array( 4, $nodeID, 0, 0, $selfPortID ); $value = implode('-', $value); array_push($treeArray, array( 'id' => $value, 'text' => $portName, 'parent' => 'O'.$nodeID, 'type' => 'port', 'data' => array('globalID' => $value) )); } } } else { $portNameFormat = json_decode($elementItem['portNameFormat'], true); $portTotal = $elementItem['portLayoutX']*$elementItem['portLayoutY']; for($x=0; $x<$portTotal; $x++) { $flagString = $this->getPortFlags($elementItem['objectID'], $elementItem['side'], $elementItem['depth'], $x); $portName = $this->generatePortName($portNameFormat, $x, $portTotal); $portName = $elementItem['portNamePrefix'].$portName.$flagString; $value = array( 4, $elementItem['objectID'], $elementItem['side'], $elementItem['depth'], $x ); $value = implode('-', $value); array_push($treeArray, array( 'id' => $value, 'text' => $portName, 'parent' => 'O'.$nodeID, 'type' => 'port', 'data' => array('globalID' => $value) )); } } } } return $treeArray; } function buildTreePorts2($objID, $objFace, $objDepth, $elementID, $forTrunk=false, $cablePortType=false, $cableMediaType=false) { $treeArray = array(); $element = $this->objectArray[$elementID]; $elementTemplateID = $element['template_id']; $elementTemplate = $this->templateArray[$elementTemplateID]; $elementTemplateFunction = $elementTemplate['templateFunction']; $object = $this->objectArray[$objID]; $objectTemplateID = $object['template_id']; $objectTemplate = $this->templateArray[$objectTemplateID]; $objectTemplateFunction = $objectTemplate['templateFunction']; $objectCompatibility = $this->compatibilityArray[$objectTemplateID][$objFace][$objDepth]; $objectPortType = $objectCompatibility['portType']; $objectMediaType = $objectCompatibility['mediaType']; $objectPortTotal = $objectCompatibility['portTotal']; $elementArray = array(); if(($forTrunk and $elementTemplateFunction != 'Endpoint') or !$forTrunk) { // Iterate over element partitions if(isset($this->compatibilityArray[$elementTemplateID])) { foreach($this->compatibilityArray[$elementTemplateID] as $elementFace => $elementFaceObj) { foreach($elementFaceObj as $elementDepth => $elementPartition) { $elementPartitionType = $elementPartition['partitionType']; $elementPartitionFunction = $elementPartition['partitionFunction']; $elementTemplateType = $elementPartition['templateType']; if($elementPartitionType == 'Enclosure') { $insertParentID = $elementID; $insertParentFace = $elementFace; $insertParentDepth = $elementDepth; // Does this partition contain inserts? while(isset($this->insertAddressArray[$insertParentID][$insertParentFace][$insertParentDepth])) { // Loop through partition inserts foreach($this->insertAddressArray[$insertParentID][$insertParentFace][$insertParentDepth] as $slotXID => $slotX) { foreach($slotX as $slotYID => $insert) { $insertID = $insert['id']; $insertName = $insert['name']; $insertTemplateID = $insert['template_id']; $insertParentID = $insert['parent_id']; // Ensure there is a compatibility entry if(isset($this->compatibilityArray[$insertTemplateID])) { // Loop through insert partitions foreach($this->compatibilityArray[$insertTemplateID] as $insertFace => $insertFaceObj) { foreach($insertFaceObj as $insertDepth => $insertPartition) { // Does this insert partition contain inserts? if(isset($this->insertAddressArray[$insertID][$insertFace][$insertDepth])) { // Insert partition is parent to a nested insert $insertParentID = $insertID; $insertParentFace = $insertFace; $insertParentDepth = $insertDepth; } else { // Cannot be a trunked endpoint if(!$this->peerArrayStandard[$insertID][$insertFace][$insertDepth]['selfEndpoint']) { $separator = ($elementPartitionFunction == 'Endpoint') ? '' : '.'; if($insertParentID) { $insertParent = $this->objectArray[$insertParentID]; $insertParentName = $insertParent['name']; $portNamePrefix = $insertParentName.$separator.$insertName.$separator; } else { $portNamePrefix = $insertName.$separator; } $rowPartitionElement = $insertPartition; $rowPartitionElement['objectID'] = $insertID; $rowPartitionElement['portNamePrefix'] = $portNamePrefix; array_push($elementArray, $rowPartitionElement); } $insertParentID = $insertParentFace = $insertParentDepth = 0; } } } } else { // This shouldn't happen, but break the loop if it does! $insertParentID = $insertParentFace = $insertParentDepth = 0; } } } } } else if($elementTemplateType == 'Insert') { // Cannot be a trunked endpoint if(!$this->peerArrayStandard[$elementID][$elementFace][$elementDepth]['selfEndpoint']) { $separator = ($elementPartitionFunction == 'Endpoint') ? '' : '.'; $rowPartitionElement = $elementPartition; $rowPartitionElement['objectID'] = $elementID; $rowPartitionElement['portNamePrefix'] = $element['name'] == '' ? '' : $element['name'].$separator; array_push($elementArray, $rowPartitionElement); } } else { // Cannot be a trunked endpoint if(!$this->peerArrayStandard[$elementID][$elementFace][$elementDepth]['selfEndpoint']) { $rowPartitionElement = $elementPartition; $rowPartitionElement['objectID'] = $elementID; $rowPartitionElement['portNamePrefix'] = ''; array_push($elementArray, $rowPartitionElement); } } } } } } foreach($elementArray as $elementItem) { $elementItemID = $elementItem['objectID']; $elementPortType = $elementItem['portType']; $elementMediaCategory = $elementItem['mediaCategory']; $elementMediaCategoryType = $elementItem['mediaCategoryType']; $elementPartitionFunction = $elementItem['partitionFunction']; if($cablePortType) { $cableMediaCategory = $this->mediaTypeByIDArray[$cableMediaType]['category_id']; // Media category must be compatible (Copper, Singlmode, Multimode) if($elementMediaCategory == $cableMediaCategory and $elementPortType == $cablePortType) { $isCompatible = true; } else if($elementPartitionFunction == 'Endpoint' and $elementPortType == $cablePortType) { $isCompatible = true; } else if($elementPortType == 4) { $isCompatible = true; } else { $isCompatible = false; } } else if($objectCompatibility) { $objectMediaCategory = $objectCompatibility['mediaCategory']; $objectMediaCategoryType = $objectCompatibility['mediaCategoryType']; $objectPortType = $objectCompatibility['portType']; $objectPartitionFunction = $objectCompatibility['partitionFunction']; // Media category must be compatible (Copper, Singlmode, Multimode) if($elementMediaCategory == $objectMediaCategory) { $isCompatible = true; // Port type must be compatible } else if($elementMediaCategoryType == $objectMediaCategoryType and ($elementPartitionFunction == 'Endpoint' or $objectPartitionFunction == 'Endpoint')) { $isCompatible = true; // If either port type is SFP, then they are compatible } else if($elementPortType == 4 or $objectPortType == 4) { $isCompatible = true; // Failing all of that, not compatible } else { $isCompatible = false; } } if($forTrunk and isset($this->peerArrayStandard[$elementID][$elementItem['side']][$elementItem['depth']])) { $isCompatible = false; } if($isCompatible) { if($elementItem['templateType'] == 'walljack') { if(isset($this->peerArrayWalljack[$elementID])) { foreach($this->peerArrayWalljack[$elementID] as $peerEntry) { $peerID = $peerEntry['id']; $peerFace = $peerEntry['face']; $peerDepth = $peerEntry['depth']; $peerPort = $peerEntry['port']; $selfPortID = $peerEntry['selfPortID']; $peerObject = $this->objectArray[$peerID]; $peerTemplateID = $peerObject['template_id']; $peerCompatibility = $this->compatibilityArray[$peerTemplateID][$peerFace][$peerDepth]; $portTotal = $peerCompatibility['portLayoutX'] * $peerCompatibility['portLayoutY']; $portNameFormat = json_decode($peerCompatibility['portNameFormat'], true); $flagString = $this->getPortFlags($elementID, 0, 0, $selfPortID); $portName = $this->generatePortName($portNameFormat, $peerPort, $portTotal); $portName = $portName.$flagString; $value = array( 4, $elementID, 0, 0, $selfPortID ); $value = implode('-', $value); array_push($treeArray, array( 'id' => $value, 'text' => $portName, 'parent' => 'O'.$elementID, 'type' => 'port', 'data' => array('globalID' => $value) )); } } } else { $portNameFormat = json_decode($elementItem['portNameFormat'], true); $portTotal = $elementItem['portLayoutX']*$elementItem['portLayoutY']; for($x=0; $x<$portTotal; $x++) { $flagString = $this->getPortFlags($elementItem['objectID'], $elementItem['side'], $elementItem['depth'], $x); $portName = $this->generatePortName($portNameFormat, $x, $portTotal); $portName = $elementItem['portNamePrefix'].$portName.$flagString; $value = array( 4, $elementItem['objectID'], $elementItem['side'], $elementItem['depth'], $x ); $value = implode('-', $value); array_push($treeArray, array( 'id' => $value, 'text' => $portName, 'parent' => 'O'.$elementID, 'type' => 'port', 'data' => array('globalID' => $value) )); } } } } return $treeArray; } function findCompatibleInserts($objectDetails, $elementDetails, &$treeArray, $originalParentID=0){ $objectID = $objectDetails['id']; $objectFunction = $objectDetails['function']; $objectPortType = $objectDetails['portType']; $objectMediaType = $objectDetails['mediaType']; $objectPortTotal = $objectDetails['portTotal']; $elementID = $elementDetails['id']; $elementFace = $elementDetails['face']; $elementDepth = $elementDetails['depth']; $element = $this->objectArray[$elementID]; $elementTemplateID = $element['template_id']; $elementTemplate = $this->templateArray[$elementTemplateID]; $elementFunction = $elementTemplate['templateFunction']; // Select all inserts that are installed in enclosure if(isset($this->insertAddressArray[$elementID][$elementFace][$elementDepth])) { foreach($this->insertAddressArray[$elementID][$elementFace][$elementDepth] as $enclosureRow) { foreach($enclosureRow as $insert) { $insertID = $insert['id']; $insertTemplateID = $insert['template_id']; if(isset($this->compatibilityArray[$insertTemplateID])) { foreach($this->compatibilityArray[$insertTemplateID] as $insertFace) { foreach($insertFace as $insertPartition) { $insertPortType = $insertPartition['portType']; $insertMediaType = $insertPartition['mediaType']; $insertPortLayoutX = $insertPartition['portLayoutX']; $insertPortLayoutY = $insertPartition['portLayoutY']; $insertPortTotal = $insertPortLayoutX * $insertPortLayoutY; $insertFace = $insertPartition['side']; $insertDepth = $insertPartition['depth']; $insertPartitionType = $insertPartition['partitionType']; $insertPortNameFormat = $insertPartition['portNameFormat']; if($insertPartitionType == 'Connectable') { if(($objectFunction == 'Endpoint' and $elementFunction == 'Passive') or ($objectFunction == 'Passive' and $elementFunction == 'Endpoint')) { if(($objectPortType == 1 or $objectPortType == 4) and ($insertPortType == 1 or $insertPortType == 4)) { $addChild = true; } else { $addChild = false; } } else if($objectFunction == 'Passive' and $elementFunction == 'Passive') { if($insertMediaType == $objectMediaType) { $addChild = true; } else { $addChild = false; } } if($addChild and $insertPortTotal == $objectPortTotal) { if($insertID != $objectID) { $addChild = true; } else { $addChild = false; } } else { $addChild = false; } if($addChild) { // Check if insert is already peered $trunkedFlag = (isset($this->peerArray[$insertID][$insertFace][$insertDepth])) ? '*' : ''; } if($addChild) { $value = array( 3, $insertID, 0, $insertDepth, 0 ); $portNameFormat = json_decode($insertPortNameFormat, true); $firstIndex = 0; $lastIndex = $insertPortTotal - 1; $firstPortName = $this->generatePortName($portNameFormat, $firstIndex, $insertPortTotal); $lastPortName = $this->generatePortName($portNameFormat, $lastIndex, $insertPortTotal); $value = implode('-', $value); $includeTree = false; $includeInsertParentName = false; $insertName = $this->generateObjectName($insertID, $includeTree, $includeInsertParentName); array_push($treeArray, array( 'id' => $value, 'text' => $insertName.'.'.$firstPortName.'-'.$lastPortName.$trunkedFlag, 'parent' => ($originalParentID != 0) ? 'O'.$originalParentID : 'O'.$elementID, 'type' => 'port', 'data' => array('globalID' => $value) )); } } else if($insertPartitionType == 'Enclosure'){ $elementDetails = array( 'id' => $insertID, 'face' => $insertFace, 'depth' => $insertDepth ); $originalParentID = $elementID; $this->findCompatibleInserts($objectDetails, $elementDetails, $treeArray, $originalParentID); } } } } } } } return; } function getPortFlags($objID, $objFace, $objDepth, $objPort) { $object = $this->objectArray[$objID]; $objectTemplateID = $object['template_id']; $template = $this->templateArray[$objectTemplateID]; $objectFunction = $template['templateFunction']; $flagsArray = array(); $flagString = ''; if(isset($this->inventoryArray[$objID][$objFace][$objDepth][$objPort])) { array_push($flagsArray, 'C'); } if(isset($this->peerArrayStandard[$objID][$objFace][$objDepth]) or isset($this->peerArrayStandardFloorplan[$objID][$objFace][$objDepth][$objPort]) or isset($this->peerArrayWalljackEntry[$objID][$objFace][$objDepth][$objPort])) { array_push($flagsArray, 'T'); } if(isset($this->populatedPortArray[$objID][$objFace][$objDepth][$objPort])) { array_push($flagsArray, 'P'); } if(count($flagsArray)) { $flagString .= ' ['; foreach($flagsArray as $index => $flag) { if(($index+1) == count($flagsArray)) { $flagString .= $flag; } else { $flagString .= $flag.','; } } $flagString .= ']'; } return $flagString; } function buildConnectorFlatPath($cable, $connectorEnd){ $returnArray = array(); if($cable[$connectorEnd.'_object_id']) { // Input variables $objectID = $cable[$connectorEnd.'_object_id']; $objectFace = $cable[$connectorEnd.'_object_face']; $objectDepth = $cable[$connectorEnd.'_object_depth']; $objectPortID = $cable[$connectorEnd.'_object_port']; // Object variables $object = $this->objectArray[$objectID]; $objectName = $object['name']; // Partition variables $partitionCompatibility = $this->compatibilityArray[$object['template_id']][$objectFace][$objectDepth]; $templateType = $partitionCompatibility['templateType']; if($templateType == 'walljack') { $peerEntry = $this->peerArrayWalljackEntry[$objectID][$objectFace][$objectDepth][$objectPortID]; $peerID = $peerEntry['id']; $peerFace = $peerEntry['face']; $peerDepth = $peerEntry['depth']; $objectPortID = $peerEntry['port']; $peer = $this->objectArray[$peerID]; $peerTemplateID = $peer['template_id']; $partitionCompatibility = $this->compatibilityArray[$peerTemplateID][$peerFace][$peerDepth]; } $partitionFunction = $partitionCompatibility['partitionFunction']; $portLayoutX = $partitionCompatibility['portLayoutX']; $portLayoutY = $partitionCompatibility['portLayoutY']; $portTotal = $portLayoutX * $portLayoutY; $portNameFormat = json_decode($partitionCompatibility['portNameFormat'],true); $portName = $this->generatePortName($portNameFormat, $objectPortID, $portTotal); // Port if($templateType == 'Insert') { if($partitionFunction == 'Endpoint') { $portString = $objectName.$portNumber; } else { $portString = '.'.$objectName.'.'.$portName; } } else { $portString = '.'.$portName; } // Object if($templateType == 'Insert') { $parentID = $object['parent_id']; $object = $this->objectArray[$parentID]; } $objectString = $object['name']; //Locations $locationString = ''; $envNodeID = $object['env_tree_id']; $rootEnvNode = false; while(!$rootEnvNode) { $envNode = $this->envTreeArray[$envNodeID]; $envNodeID = $envNode['parent']; $rootEnvNode = $envNodeID == '#' or !isset($this->envTreeArray[$envNodeID]) ? true : false; $locationString = $envNode['name'].'.'.$locationString; } $flatPath = $locationString.$objectString.$portString; } else { $flatPath = 'None'; } return $flatPath; } function getCableUnitOfLength($mediaTypeID){ $mediaCategoryTypeID = $this->mediaTypeValueArray[$mediaTypeID]['category_type_id']; return $this->mediaCategoryTypeArray[$mediaCategoryTypeID]['unit_of_length']; } function clearInventoryTable($objID, $objFace, $objDepth, $objPort){ if($inventory = $this->inventoryArray[$objID][$objFace][$objDepth][$objPort]) { foreach($inventory as $inventoryEntryIndex => $inventoryEntry) { $rowID = $inventoryEntry['rowID']; if($inventoryEntry['localEndID'] === 0 and $inventoryEntry['remoteEndID'] === 0) { // If this is an unmanaged connection, delete the entry $this->qls->SQL->delete('app_inventory', array('id' => array('=', $rowID))); } else { // If this is a managed connection, just clear the data $attrPrefix = $inventoryEntry['localAttrPrefix']; $set = array( $attrPrefix.'_object_id' => 0, $attrPrefix.'_object_face' => 0, $attrPrefix.'_object_depth' => 0, $attrPrefix.'_port_id' => 0 ); $this->qls->SQL->update('app_inventory', $set, array('id' => array('=', $rowID))); if(isset($this->inventoryArray[$inventoryEntry['id']][$inventoryEntry['face']][$inventoryEntry['depth']][$inventoryEntry['port']][$inventoryEntryIndex])) { $this->inventoryArray[$inventoryEntry['id']][$inventoryEntry['face']][$inventoryEntry['depth']][$inventoryEntry['port']][$inventoryEntryIndex]['id'] = 0; $this->inventoryArray[$inventoryEntry['id']][$inventoryEntry['face']][$inventoryEntry['depth']][$inventoryEntry['port']][$inventoryEntryIndex]['face'] = 0; $this->inventoryArray[$inventoryEntry['id']][$inventoryEntry['face']][$inventoryEntry['depth']][$inventoryEntry['port']][$inventoryEntryIndex]['depth'] = 0; $this->inventoryArray[$inventoryEntry['id']][$inventoryEntry['face']][$inventoryEntry['depth']][$inventoryEntry['port']][$inventoryEntryIndex]['port'] = 0; } } } unset($this->inventoryArray[$objID][$objFace][$objDepth][$objPort]); } } function clearPopulatedTable($objID, $objFace, $objDepth, $objPort){ if($populatedPortEntry = $this->populatedPortArray[$objID][$objFace][$objDepth][$objPort]) { $rowID = $populatedPortEntry['rowID']; $this->qls->SQL->delete('app_populated_port', array('id' => array('=', $rowID))); unset($this->populatedPortArray[$objID][$objFace][$objDepth][$objPort]); } } // Not sure if this is useful :/ function clearPeerTable($rowID){ //$qls->SQL->delete('app_object_peer', array('id' => array('=', $rowID))); //unset($qls->App->peerArrayWalljack[$entry['selfID']]); } function calculateCableLength($mediaType, $length, $includeUnit=true) { // Collect details about the cable to help us calculate length $mediaCategoryTypeID = $this->mediaTypeValueArray[$mediaType]['category_type_id']; $mediaCategoryType = $this->mediaCategoryTypeArray[$mediaCategoryTypeID]; $mediaCategoryTypeName = strtolower($mediaCategoryType['name']); if($length == 0) { $lengthString = 'Unk. Length'; $includeUnit = false; } else if($mediaCategoryTypeName == 'copper') { // Convert to feet $lengthString = $this->convertToHighestHalfFeet($length); } else if($mediaCategoryTypeName == 'fiber') { // Convert to meters $lengthString = $this->convertToHighestHalfMeter($length); } else { $lengthString = $length; } if($includeUnit) { $lengthString = $lengthString.' '.$mediaCategoryType['unit_of_length']; } return $lengthString; } function convertToHighestHalfMeter($millimeter){ $meters = $millimeter * 0.001; return round($meters * 2) / 2; } function convertToHighestHalfFeet($millimeter){ $feet = $millimeter * 0.00328084; return round($feet * 2) / 2; } function convertFeetToMillimeters($cableLength){ $meters = $cableLength * 0.3048; $millimeters = $meters * 1000; return $millimeters; } function convertMetersToMillimeters($cableLength){ $millimeters = $cableLength * 1000; return $millimeters; } function logAction($function, $actionType, $actionString){ $columns = array('date', 'function', 'action_type', 'user_id', 'action'); $values = array(time(), $function, $actionType, $this->qls->user_info['id'], $actionString); $this->qls->SQL->insert('app_history', $columns, $values); } function buildPathFull($path, $connectorCode39){ $htmlPathFull = ''; $htmlPathFull .= '
| if($objectIndex == 0 or (($objectIndex == count($path)-1) and ($path[$objectIndex-1]['type'] == 'cable'))) { array_push($tableArray[count($tableArray)-1], ' | '.$this->wrapObject(0, 'None').' | '); } $connectorTypeID = $object['data']['connectorType']; if($connectorTypeID != 0) { $connectorTypeName = $this->connectorTypeValueArray[$connectorTypeID]['name']; $connectorHTML = ''; } else { $connectorTypeName = 'Unk'; $connectorHTML = ''; } // Wrap inand add to row array $htmlString = ' | '.$connectorHTML.' | '; array_push($tableArray[count($tableArray)-1], $htmlString); if($objectIndex == count($path)-1) { array_push($tableArray[count($tableArray)-1], ''); } } break; case 'cable': $cableTypeID = $object['data']['mediaTypeID']; if($cableTypeID != 0) { $cableTypeName = $mediaTypeClass = $this->mediaTypeValueArray[$cableTypeID]['name']; } else { $cableTypeName = 'Unk. Media Type'; $mediaTypeClass = 'Unk'; } $cableLength = $object['data']['length']; $htmlString = ' | and add to row array $htmlString = ' | '.$htmlString.' | '; array_push($tableArray[count($tableArray)-1], $htmlString); // Add new row array in table array array_push($tableArray, array()); break; case 'object': $objID = $object['data']['id']; $objFace = $object['data']['face']; $objDepth = $object['data']['depth']; $objPort = $object['data']['port']; $selected = $object['data']['selected']; $objName = $this->generateObjectPortName($objID, $objFace, $objDepth, $objPort); $objBox = $this->wrapObject($objID, $objName, $selected); // Wrap inand add to row array $htmlString = ' | '.$objBox.' | '; array_push($tableArray[count($tableArray)-1], $htmlString); if($path[$objectIndex+1]['type'] == 'trunk') { if(isset($path[$objectIndex-1])) { $connectorTypeID = $path[$objectIndex-1]['data']['connectorType']; if($connectorTypeID != 0) { $connectorTypeName = $this->connectorTypeValueArray[$connectorTypeID]['name']; $connectorHTML = ''; } else { $connectorTypeName = 'Unk'; $connectorHTML = ''; } // Wrap inand add to row array $htmlString = ' | '.$connectorHTML.' | '; array_push($tableArray[count($tableArray)-1], $htmlString); array_push($tableArray[count($tableArray)-1], ''); } else { array_push($tableArray[count($tableArray)-1], ' | '); array_push($tableArray[count($tableArray)-1], ' | '); } // Add new row array in table array array_push($tableArray, array()); } break; case 'trunk': $htmlString = ' | and add to row array $htmlString = ' | '.$htmlString.' | '; array_push($tableArray[count($tableArray)-1], $htmlString); // Add new row array in table array array_push($tableArray, array()); break; } } } else { foreach($path as $objectIndex => $object) { $objType = $object['type']; switch($objType) { case 'object': if($objectIndex) { if($path[$objectIndex+1]['type'] == 'trunk') { $bottomTableTag = ''; } else { $bottomTableTag = ''; } } else { $bottomTableTag = ''; } $topTableTag = ' |
| '; $htmlPathFull .= $topTableTag; $objID = $object['data']['id']; $objFace = $object['data']['face']; $objDepth = $object['data']['depth']; $objPort = $object['data']['port']; $selected = $object['data']['selected']; $objName = $this->generateObjectPortName($objID, $objFace, $objDepth, $objPort); $objBox = $this->wrapObject($objID, $objName, $selected); $htmlPathFull .= $objBox; $htmlPathFull .= $bottomTableTag; break; case 'connector': $htmlPathFull .= ' | |
| ';
$connectorTypeID = $object['data']['connectorType'];
if($connectorTypeID != 0) {
$connectorTypeName = $this->connectorTypeValueArray[$connectorTypeID]['name'];
$code39 = $object['data']['code39'];
$connectorClass = $code39 != 0 ? 'cableConnector cursorPointer' : '';
$htmlPathFull .= '';
//$htmlPathFull .= '';
} else {
$connectorTypeName = 'Unk';
$htmlPathFull .= ' ';
//$htmlPathFull .= ' ';
}
$htmlPathFull .= ' | |
| ';
$cableTypeID = $object['data']['mediaTypeID'];
if($cableTypeID != 0) {
$cableTypeName = $mediaTypeClass = $this->mediaTypeValueArray[$cableTypeID]['name'];
} else {
$cableTypeName = 'Unk. Media Type';
$mediaTypeClass = 'Unk';
}
$cableLength = $object['data']['length'];
$htmlPathFull .= ' ';
$htmlPathFull .= $cableLength.' ';
$htmlPathFull .= ''.$cableTypeName; $htmlPathFull .= ' | ';
$htmlPathFull .= ' ';
$htmlPathFull .= ' | ';
break;
}
}
}
$htmlPathFull .= '