SQL->select('*', 'app_object_templates');
while($row = $qls->SQL->fetch_assoc($result)){
$return[$row['id']] = $row;
}
return $return;
}
function buildCompatibilityTable(&$qls){
$return = array();
$result = $qls->SQL->select('*', 'app_object_compatibility');
while($row = $qls->SQL->fetch_assoc($result)){
$return[$row['template_id']][$row['side']][$row['depth']] = $row;
}
return $return;
}
function buildLocation($elementID, &$qls){
$children = array();
$result = $qls->SQL->select('*', 'app_env_tree', array('parent' => array('=', $elementID)), array('name', 'ASC'));
while ($row = $qls->SQL->fetch_assoc($result)) {
if($row['type'] == 'location' || $row['type'] == 'pod') {
$elementType = 0;
} else if($row['type'] == 'cabinet') {
$elementType = 1;
}
$value = array(
$elementType,
$row['id'],
0,
0,
0
);
$value = implode('-', $value);
array_push($children, array(
'value' => $value,
'text' => $row['name']
)
);
}
if($elementID == '#') {
array_push($children, array(
'text' => '----',
'children' => array(
array(
'value' => '0-0-0-0-0',
'text' => 'Clear'
)
)
)
);
}
return $children;
}
function buildObjects($elementID, $object, $objectFace, $partitionDepth, &$qls){
$children = array();
$templateTable = buildTemplateTable($qls);
$objectFunction = $templateTable[$object['template_id']]['templateFunction'];
$query = $qls->SQL->select('*', 'app_object_compatibility', array('template_id' => array('=', $object['template_id']), 'AND', 'side' => array('=', $objectFace), 'AND', 'depth' => array('=', $partitionDepth)));
$objectCompatibility = $qls->SQL->fetch_assoc($query);
if($objectCompatibility['partitionFunction'] == 'Endpoint') {
$query = $qls->SQL->select(
'*',
'app_object_compatibility',
'portTotal = '.$objectCompatibility['portTotal'].' AND portType = 1 AND partitionFunction <> "Endpoint"'
);
} else if($objectCompatibility['partitionFunction'] == 'Passive' and $objectCompatibility['portType'] == 1) {
$query = $qls->SQL->select(
'*',
'app_object_compatibility',
'portTotal = '.$objectCompatibility['portTotal'].' AND ((partitionFunction = "Endpoint" AND (portType = 1 OR portType = 4)) OR (partitionFunction = "Passive" AND mediaType = '.$objectCompatibility['mediaType'].'))'
);
} else if($objectCompatibility['partitionFunction'] == 'Passive') {
$query = $qls->SQL->select(
'*',
'app_object_compatibility',
array(
'portTotal' => array('=', $objectCompatibility['portTotal']),
'AND',
'mediaType' => array('=', $objectCompatibility['mediaType']),
'AND',
'partitionFunction' => array('=', 'Passive')
)
//'portTotal = '.$objectCompatibility['portTotal'].' AND mediaType = '.$objectCompatibility['mediaType'].' AND partitionFunction = "Passive"'
);
}
$compatibleObjectsArray = array();
$compatibleEnclosureArray = array();
while ($row = $qls->SQL->fetch_assoc($query)) {
if($row['templateType'] == 'Insert') {
$queryInsert = $qls->SQL->select('*', 'app_object', array('env_tree_id' => array('=', $elementID), 'AND', 'template_id' => array('=', $row['template_id'])));
while ($rowInsert = $qls->SQL->fetch_assoc($queryInsert)) {
array_push($compatibleEnclosureArray, $rowInsert['parent_id']);
}
} else if($row['templateType'] == 'Standard') {
array_push($compatibleObjectsArray, $row['template_id']);
}
}
$compatibleObjectsArray = array_unique($compatibleObjectsArray);
$compatibleEnclosureArray = array_unique($compatibleEnclosureArray);
$query = $qls->SQL->select('*', 'app_object', array('env_tree_id' => array('=', $elementID), 'AND', 'parent_id' => array('=', 0), 'AND', 'id' => array('<>', $object['id'])), array('name', 'ASC'));
while ($row = $qls->SQL->fetch_assoc($query)) {
if(in_array($row['template_id'], $compatibleObjectsArray) or in_array($row['id'], $compatibleEnclosureArray)) {
$mountConfig = $templateTable[$row['template_id']]['templateMountConfig'];
for($x=0; $x<=$mountConfig; $x++){
if($mountConfig == 1) {
$side = $x == 0 ? '(front)' : '(rear)';
} else {
$side = '';
}
$value = array(
2,
$row['id'],
$x,
0,
0
);
$value = implode('-', $value);
array_push($children, array(
'value' => $value,
//'text' => $row['name'].$side
'text' => $row['name']
)
);
}
}
}
return $children;
}
function buildObjectsConnector($elementID, $cable, $connectorAttributePrefix, &$qls){
$children = array();
$templateTable = buildTemplateTable($qls);
$connectorType = $cable[$connectorAttributePrefix.'_connector'];
$cableMediaType = $cable['mediaType'];
//$query = $qls->SQL->select('*', 'app_object_compatibility', '(portType = '.$connectorType.' OR portType = 4) AND (mediaType = '.$cableMediaType.' OR partitionFunction = "Endpoint")');
$query = $qls->SQL->select('*', 'app_object_compatibility', 'portType = '.$connectorType.' OR portType = 4');
$compatibleObjectsArray = array();
$compatibleEnclosureArray = array();
while ($row = $qls->SQL->fetch_assoc($query)) {
if($row['templateType'] == 'Insert') {
$queryInsert = $qls->SQL->select('*', 'app_object', array('env_tree_id' => array('=', $elementID), 'AND', 'template_id' => array('=', $row['template_id'])));
while ($rowInsert = $qls->SQL->fetch_assoc($queryInsert)) {
array_push($compatibleEnclosureArray, $rowInsert['parent_id']);
}
} else if($row['templateType'] == 'Standard') {
array_push($compatibleObjectsArray, $row['template_id']);
}
}
$compatibleObjectsArray = array_unique($compatibleObjectsArray);
$compatibleEnclosureArray = array_unique($compatibleEnclosureArray);
$query = $qls->SQL->select('*', 'app_object', array('env_tree_id' => array('=', $elementID), 'AND', 'parent_id' => array('=', 0)));
while ($row = $qls->SQL->fetch_assoc($query)) {
if(in_array($row['template_id'], $compatibleObjectsArray) or in_array($row['id'], $compatibleEnclosureArray)) {
$mountConfig = $templateTable[$row['template_id']]['templateMountConfig'];
for($x=0; $x<=$mountConfig; $x++){
if($mountConfig == 1) {
$side = $x == 0 ? ' (front)' : ' (rear)';
} else {
$side = '';
}
$value = array(
2,
$row['id'],
$x,
0,
0
);
$value = implode('-', $value);
array_push($children, array(
'value' => $value,
//'text' => $row['name'].$side
'text' => $row['name']
)
);
}
}
}
return $children;
}
function buildObjectsPathFinder($elementID, $objectID, $objectFace, $objectDepth, &$qls){
$children = array();
$templateTable = buildTemplateTable($qls);
$query = $qls->SQL->select('*', 'app_object', array('id' => array('=', $objectID)));
$object = $qls->SQL->fetch_assoc($query);
$query = $qls->SQL->select('*', 'app_object_compatibility', array('template_id' => array('=', $object['template_id']), 'AND', 'side' => array('=', $objectFace), 'AND', 'depth' => array('=', $objectDepth)));
$objectCompatibility = $qls->SQL->fetch_assoc($query);
$mediaType = $objectCompatibility['mediaType'];
$mediaCategory = $objectCompatibility['mediaCategory'];
$mediaCategoryType = $objectCompatibility['mediaCategoryType'];
if($mediaType == 8) {
if($mediaCategory == 5) {
if($mediaCategoryType == 4) {
$compatibilityQuery = array('partitionType' => array('=', 'connectable'));
} else {
$compatibilityQuery = array('mediaCategoryType' => array('=', $mediaCategoryType));
}
} else {
$compatibilityQuery = array('mediaCategory' => array('=', $mediaCategory));
}
} else {
$compatibilityQuery = array('mediaType' => array('=', $mediaType));
}
$query = $qls->SQL->select('*', 'app_object_compatibility', $compatibilityQuery);
$compatibleObjectsArray = array();
$compatibleEnclosureArray = array();
while ($row = $qls->SQL->fetch_assoc($query)) {
if($row['templateType'] == 'Insert') {
$queryInsert = $qls->SQL->select('*', 'app_object', array('env_tree_id' => array('=', $elementID), 'AND', 'template_id' => array('=', $row['template_id'])));
while ($rowInsert = $qls->SQL->fetch_assoc($queryInsert)) {
array_push($compatibleEnclosureArray, $rowInsert['parent_id']);
}
} else if($row['templateType'] == 'Standard') {
array_push($compatibleObjectsArray, $row['template_id']);
}
}
$compatibleObjectsArray = array_unique($compatibleObjectsArray);
$compatibleEnclosureArray = array_unique($compatibleEnclosureArray);
$query = $qls->SQL->select('*', 'app_object', array('env_tree_id' => array('=', $elementID), 'AND', 'parent_id' => array('=', 0)), array('name', 'ASC'));
while ($row = $qls->SQL->fetch_assoc($query)) {
if(in_array($row['template_id'], $compatibleObjectsArray) or in_array($row['id'], $compatibleEnclosureArray)) {
$mountConfig = $templateTable[$row['template_id']]['templateMountConfig'];
for($x=0; $x<=$mountConfig; $x++){
if($mountConfig == 1) {
$side = $x == 0 ? ' (front)' : ' (rear)';
} else {
$side = '';
}
$value = array(
2,
$row['id'],
$x,
0,
0
);
$value = implode('-', $value);
array_push($children, array(
'value' => $value,
//'text' => $row['name'].$side
'text' => $row['name']
)
);
}
}
}
return $children;
}
function buildPartitions($elementID, $elementFace, $object, $objectFace, $partitionDepth, &$qls){
$children = array();
$templateTable = buildTemplateTable($qls);
$query = $qls->SQL->select('*', 'app_object', array('id' => array('=', $elementID)));
$element = $qls->SQL->fetch_assoc($query);
$query = $qls->SQL->select('*', 'app_object_compatibility', array('template_id' => array('=', $object['template_id']), 'AND', 'side' => array('=', $objectFace), 'AND', 'depth' => array('=', $partitionDepth)));
$objectCompatibility = $qls->SQL->fetch_assoc($query);
// Passive/Endpoint
$objectFunction = $templateTable[$object['template_id']]['templateFunction'];
$elementFunction = $templateTable[$element['template_id']]['templateFunction'];
$elementType = $templateTable[$element['template_id']]['templateType'];
// Find element partitions
$query = $qls->SQL->select('*','app_object_compatibility',array('template_id' => array('=',$element['template_id']),'AND','side' => array('=',$elementFace)));
while($row = $qls->SQL->fetch_assoc($query)) {
if($row['partitionType'] == 'Connectable') {
if($row['portTotal'] == $objectCompatibility['portTotal']) {
if($objectFunction == 'Endpoint' or $elementFunction == 'Endpoint') {
if(($objectCompatibility['portType'] == 1 or $objectCompatibility['portType'] == 4) and ($row['portType'] == 1 or $row['portType'] == 4)) {
$addChild = true;
} else {
$addChild = false;
}
} else if($row['mediaType'] == $objectCompatibility['mediaType']) {
$addChild = true;
} else {
$addChild = false;
}
if($addChild) {
if($elementType == 'Insert') {
if($elementFunction == 'Passive') {
$insertNamePrefix = $element['name'].'.';
} else {
$insertNamePrefix = $element['name'];
}
} else {
$insertNamePrefix = '';
}
$value = array(
3,
$elementID,
$elementFace,
$row['depth'],
0
);
$portCount = $row['portLayoutX']*$row['portLayoutY'];
$portStart = $row['portNumber'];
$portEnd = $portStart + ($portCount - 1);
$value = implode('-', $value);
array_push($children, array(
'value' => $value,
'text' => $insertNamePrefix.$row['portPrefix'].$portStart.'‑'.$portEnd
)
);
}
}
} else if($row['partitionType'] == 'Enclosure') {
$queryInserts = $qls->SQL->select(
'*',
'app_object',
array(
'parent_id' => array(
'=',
$elementID
),
'AND',
'parent_face' => array(
'=',
$elementFace
),
'AND',
'parent_depth' => array(
'=',
$row['depth']
)
)
);
while($insert = $qls->SQL->fetch_assoc($queryInserts)){
$queryCompatibility = $qls->SQL->select('*', 'app_object_compatibility', array('template_id' => array('=', $insert['template_id'])));
$insertCompatibility = $qls->SQL->fetch_assoc($queryCompatibility);
if(($objectFunction == 'Endpoint' and $elementFunction == 'Passive') or ($objectFunction == 'Passive' and $elementFunction == 'Endpoint')) {
if(($objectCompatibility['portType'] == 1 or $objectCompatibility['portType'] == 4) and ($insertCompatibility['portType'] == 1 or $insertCompatibility['portType'] == 4)) {
$addChild = true;
} else {
$addChild = false;
}
} else if($objectFunction == 'Passive' and $elementFunction == 'Passive') {
if($insertCompatibility['mediaType'] == $objectCompatibility['mediaType']) {
$addChild = true;
} else {
$addChild = false;
}
}
if($addChild and $insertCompatibility['portTotal'] == $objectCompatibility['portTotal']) {
if($insert['id'] != $object['id']) {
// Check if insert is already peered
$queryInsertPeer = $qls->SQL->select('*', 'app_object_peer', array('a_id' => array('=', $insert['id']), 'OR', 'b_id' => array('=', $insert['id'])));
if($qls->SQL->num_rows($queryInsertPeer) == 0) {
$addChild = true;
} else {
$addChild = false;
}
} else {
$addChild = false;
}
} else {
$addChild = false;
}
if($addChild) {
$value = array(
3,
$insert['id'],
0,
0,
0
);
$portCount = $insertCompatibility['portLayoutX']*$insertCompatibility['portLayoutY'];
$portStart = $insertCompatibility['portNumber'];
$portEnd = $portStart + ($portCount - 1);
$value = implode('-', $value);
array_push($children, array(
'value' => $value,
'text' => $insert['name'].'.'.$insertCompatibility['portPrefix'].$portStart.'‑'.$portEnd
)
);
}
}
}
}
return $children;
}
function buildPorts($elementID, $elementFace, $cable, $connectorAttributePrefix, &$qls){
$children = array();
$query = $qls->SQL->select('*', 'app_object', array('id' => array('=', $elementID)));
$element = $qls->SQL->fetch_assoc($query);
$object = $cable[$connectorAttributePrefix.'_object_id'];
$depth = $cable[$connectorAttributePrefix.'_object_depth'];
$port = $cable[$connectorAttributePrefix.'_port_id'];
$mediaTypeArray = array();
$query = $qls->SQL->select('*', 'shared_mediaType');
while($row = $qls->SQL->fetch_assoc($query)) {
$mediaTypeArray[$row['value']] = $row;
}
$occupiedPorts = array();
$query = $qls->SQL->select('*', 'app_inventory');
while($row = $qls->SQL->fetch_assoc($query)){
$attrPrefixArray = array('a','b');
foreach($attrPrefixArray as $attrPrefix) {
if($row[$attrPrefix.'_object_id'] != 0) {
if($row[$attrPrefix.'_object_id'] != $object or $row[$attrPrefix.'_object_depth'] != $depth or $row[$attrPrefix.'_port_id'] != $port) {
$portValue = $row[$attrPrefix.'_object_id'].'-'.$row[$attrPrefix.'_object_face'].'-'.$row[$attrPrefix.'_object_depth'].'-'.$row[$attrPrefix.'_port_id'];
array_push($occupiedPorts, $portValue);
}
}
}
}
/*
// Identify occupied ports of the element
$query = $qls->SQL->select('*', 'app_inventory', '(a_object_id = '.$elementID.' AND a_object_face = '.$elementFace.') OR (b_object_id = '.$elementID.' AND b_object_face = '.$elementFace.')');
while($row = $qls->SQL->fetch_assoc($query)){
$attrPrefixArray = array('a','b');
foreach($attrPrefixArray as $attrPrefix) {
if($row[$attrPrefix.'_object_id'] == $elementID and $row[$attrPrefix.'_object_face'] == $elementFace) {
if($row[$attrPrefix.'_object_depth'] != $depth or $row[$attrPrefix.'_port_id'] != $port) {
$portValue = $row[$attrPrefix.'_object_id'].'-'.$row[$attrPrefix.'_object_face'].'-'.$row[$attrPrefix.'_object_depth'].'-'.$row[$attrPrefix.'_port_id'];
array_push($occupiedPorts, $portValue);
}
}
}
}
// Identify occupied ports of inserts which are installed in the element
$query = $qls->SQL->select('*', 'app_object', array('parent_id' => array('=', $elementID), 'AND', 'parent_face' => array('=', $elementFace)));
while($row = $qls->SQL->fetch_assoc($query)){
$queryInsert = $qls->SQL->select('*', 'app_inventory', '(a_object_id = '.$row['id'].') OR (b_object_id = '.$row['id'].')');
while($rowInsert = $qls->SQL->fetch_assoc($queryInsert)){
$attrPrefixArray = array('a','b');
foreach($attrPrefixArray as $attrPrefix) {
if($rowInsert[$attrPrefix.'_object_id'] == $row['id']) {
if($rowInsert[$attrPrefix.'_object_depth'] != $depth or $rowInsert[$attrPrefix.'_port_id'] != $port) {
$portValue = $queryInsert[$attrPrefix.'_object_id'].'-'.$queryInsert[$attrPrefix.'_object_face'].'-'.$queryInsert[$attrPrefix.'_object_depth'].'-'.$queryInsert[$attrPrefix.'_port_id'];
array_push($occupiedPorts, $portValue);
}
}
}
}
}
*/
// Retrieve selected object partitions
$query = $qls->SQL->select('*',
'app_object_compatibility',
array(
'template_id' => array(
'=',
$element['template_id']
),
'AND',
'side' => array(
'=',
$elementFace
)
)
);
while($row = $qls->SQL->fetch_assoc($query)){
$elementArray = array();
if($row['partitionType'] == 'Enclosure') {
$queryInsertObject = $qls->SQL->select(
'*',
'app_object',
array(
'parent_id' => array(
'=',
$elementID
),
'AND',
'parent_face' => array(
'=',
$row['side']
),
'AND',
'parent_depth' => array(
'=',
$row['depth']
)
)
);
while($rowInsertObject = $qls->SQL->fetch_assoc($queryInsertObject)) {
$queryInsertPartition = $qls->SQL->select('*', 'app_object_compatibility', array('template_id' => array('=', $rowInsertObject['template_id'])));
while($rowInsertPartition = $qls->SQL->fetch_assoc($queryInsertPartition)) {
if(!isObjectTrunkedAndEndpoint($rowInsertObject['id'], 0, $rowInsertPartition['depth'], $qls)) {
$rowInsertElement = $rowInsertPartition;
$rowInsertElement['objectID'] = $rowInsertObject['id'];
$rowInsertElement['portPrefix'] = $rowInsertObject['name'] == '' ? $rowInsertElement['portPrefix'] : $rowInsertObject['name'].'.'.$rowInsertElement['portPrefix'];
array_push($elementArray, $rowInsertElement);
}
}
}
} else if($row['templateType'] == 'Insert') {
if(!isObjectTrunkedAndEndpoint($elementID, $elementFace, $row['depth'], $qls)) {
$separator = $row['partitionFunction'] == 'Endpoint' ? '' : '.';
$rowPartitionElement = $row;
$rowPartitionElement['objectID'] = $elementID;
$rowPartitionElement['portPrefix'] = $element['name'] == '' ? $rowPartitionElement['portPrefix'] : $element['name'].$separator.$rowPartitionElement['portPrefix'];
array_push($elementArray, $rowPartitionElement);
}
} else {
if(!isObjectTrunkedAndEndpoint($elementID, $elementFace, $row['depth'], $qls)) {
$rowPartitionElement = $row;
$rowPartitionElement['objectID'] = $elementID;
array_push($elementArray, $rowPartitionElement);
}
}
foreach($elementArray as $elementItem) {
$cablePortType = $cable[$connectorAttributePrefix.'_connector'];
$cableMediaCategory = $mediaTypeArray[$cable['mediaType']]['category_id'];
$elementPortType = $elementItem['portType'];
$elementMediaCategory = $mediaTypeArray[$elementItem['mediaType']]['category_id'];
$elementPartitionFunction = $elementItem['partitionFunction'];
if(($elementPortType == $cablePortType or $elementPortType == 4) and ($elementMediaCategory == $cableMediaCategory or $elementPartitionFunction == 'Endpoint')) {
$portStart = $elementItem['portNumber'];
$portIndex = 0;
$portCount = $elementItem['portLayoutX']*$elementItem['portLayoutY'];
for($x=$portIndex; $x<$portCount; $x++) {
$portValue = $elementItem['objectID'].'-'.$elementItem['side'].'-'.$elementItem['depth'].'-'.$x;
// Test if port is already connected
if(!in_array($portValue, $occupiedPorts)) {
$portNumber = $portStart+$x;
$value = array(
4,
$elementItem['objectID'],
$elementItem['side'],
$elementItem['depth'],
$portIndex+$x
);
$value = implode('-', $value);
array_push($children, array(
'value' => $value,
'text' => $elementItem['portPrefix'].$portNumber
)
);
}
}
}
}
}
return $children;
}
function buildPortsPathFinder($elementID, $elementFace, $selectedObjID, $selectedObjFace, $selectedObjDepth, $selectedObjectPortID, &$qls){
$children = array();
$compatibilityTable = buildCompatibilityTable($qls);
$query = $qls->SQL->select('*', 'app_object', array('id' => array('=', $elementID)));
$element = $qls->SQL->fetch_assoc($query);
$query = $qls->SQL->select('*', 'app_object', array('id' => array('=', $selectedObjID)));
$object = $qls->SQL->fetch_assoc($query);
$mediaCategory = $compatibilityTable[$object['template_id']][$selectedObjFace][$selectedObjDepth];
$mediaType = $compatibilityTable[$object['template_id']][$selectedObjFace][$selectedObjDepth]['mediaType'];
$mediaCategory = $compatibilityTable[$object['template_id']][$selectedObjFace][$selectedObjDepth]['mediaCategory'];
$mediaCategoryType = $compatibilityTable[$object['template_id']][$selectedObjFace][$selectedObjDepth]['mediaCategoryType'];
if($mediaType == 8) {
if($mediaCategory == 5) {
if($mediaCategoryType == 4) {
$compatibilityAttr = 'partitionType';
$compatibilityValue = 'Connectable';
} else {
$compatibilityAttr = 'mediaCategoryType';
$compatibilityValue = $mediaCategoryType;
}
} else {
$compatibilityAttr = 'mediaCategory';
$compatibilityValue = $mediaCategory;
}
} else {
$compatibilityAttr = 'mediaType';
$compatibilityValue = $mediaType;
}
// Build array containing ports that are already connected
$occupiedPorts = array();
$query = $qls->SQL->select('*', 'app_inventory', 'a_object_id = '.$elementID.' AND a_object_face = '.$elementFace);
while($row = $qls->SQL->fetch_assoc($query)){
if($row['a_object_id'] != $selectedObjectID or $row['a_object_depth'] != $selectedObjectDepth or $row['a_port_id'] != $selectedObjectPortID) {
$portValue = $row['a_object_depth'].'-'.$row['a_port_id'];
array_push($occupiedPorts, $portValue);
}
}
$query = $qls->SQL->select('*', 'app_inventory', 'b_object_id = '.$elementID.' AND b_object_face = '.$elementFace);
while($row = $qls->SQL->fetch_assoc($query)){
if($row['b_object_id'] != $selectedObjectID or $row['b_object_depth'] != $selectedObjectDepth or $row['b_port_id'] != $selectedObjectPortID) {
$portValue = $row['b_object_depth'].'-'.$row['b_port_id'];
array_push($occupiedPorts, $portValue);
}
}
$occupiedPorts = array_unique($occupiedPorts);
$query = $qls->SQL->select('*',
'app_object_compatibility',
array(
'template_id' => array(
'=',
$element['template_id']
),
'AND',
'side' => array(
'=',
$elementFace
)
)
);
$elementArray = array();
while($row = $qls->SQL->fetch_assoc($query)){
if($row['partitionType'] == 'Enclosure') {
// Find all the inserts installed in the enclosure
$queryInsertObject = $qls->SQL->select(
'*',
'app_object',
array(
'parent_id' => array(
'=',
$elementID
),
'AND',
'parent_face' => array(
'=',
$row['side']
),
'AND',
'parent_depth' => array(
'=',
$row['depth']
)
)
);
while($rowInsertObject = $qls->SQL->fetch_assoc($queryInsertObject)) {
$queryInsertPartitions = $qls->SQL->select('*', 'app_object_compatibility', array('template_id' => array('=', $rowInsertObject['template_id'])));
while($rowInsertPartition = $qls->SQL->fetch_assoc($queryInsertPartitions)) {
if(!isObjectTrunkedAndEndpoint($rowInsertObject['id'], 0, $rowInsertPartition['depth'], $qls) or $row['partitionFunction'] == 'Endpoint') {
// Determine if the insert port media is compatible with the clicked object's port
$queryInsertCompatibility = $qls->SQL->select('*',
'app_object_compatibility',
array(
'template_id' => array(
'=',
$rowInsertObject['template_id']
),
'AND',
$compatibilityAttr => array(
'=',
$compatibilityValue
),
'AND',
'depth' => array(
'=',
$rowInsertPartition['depth']
)
)
);
if($qls->SQL->num_rows($queryInsertCompatibility)) {
$rowInsertElement = $qls->SQL->fetch_assoc($queryInsertCompatibility);
$separator = $rowInsertElement['partitionFunction'] == 'Endpoint' ? '' : '.';
$rowInsertElement['objectID'] = $rowInsertObject['id'];
$rowInsertElement['portPrefix'] = $rowInsertObject['name'] == '' ? $rowInsertElement['portPrefix'] : $rowInsertObject['name'].$separator.$rowInsertElement['portPrefix'];
array_push($elementArray, $rowInsertElement);
}
}
}
}
} else if($row['templateType'] == 'Insert') {
if(!isObjectTrunkedAndEndpoint($elementID, $elementFace, $row['depth'], $qls) or $row['partitionFunction'] == 'Endpoint') {
if($row[$compatibilityAttr] == $compatibilityValue) {
$separator = $row['partitionFunction'] == 'Endpoint' ? '' : '.';
$rowPartitionElement = $row;
$rowPartitionElement['objectID'] = $elementID;
$rowPartitionElement['portPrefix'] = $element['name'] == '' ? $rowPartitionElement['portPrefix'] : $element['name'].$separator.$rowPartitionElement['portPrefix'];
array_push($elementArray, $rowPartitionElement);
}
}
} else {
if(!isObjectTrunkedAndEndpoint($elementID, $elementFace, $row['depth'], $qls) or $row['partitionFunction'] == 'Endpoint') {
if($row[$compatibilityAttr] == $compatibilityValue) {
$rowPartitionElement = $row;
$rowPartitionElement['objectID'] = $elementID;
array_push($elementArray, $rowPartitionElement);
}
}
}
}
foreach($elementArray as $element) {
$portStart = $element['portNumber'];
$portIndex = 0;
$portCount = $element['portLayoutX']*$element['portLayoutY'];
for($x=$portIndex; $x<$portCount; $x++) {
$portValue = $element['depth'].'-'.$x;
// Test if port is already connected
if(!in_array($portValue, $occupiedPorts)) {
$portNumber = $portStart+$x;
$value = array(
4,
$element['objectID'],
$element['side'],
$element['depth'],
$portIndex+$x
);
$value = implode('-', $value);
array_push($children, array(
'value' => $value,
'text' => $element['portPrefix'].$portNumber
)
);
}
}
}
return $children;
}
function buildConnectorPath($cable, $connectorAttributePrefix, &$qls){
$returnArray = array();
$objectID = $cable[$connectorAttributePrefix.'_object_id'];
$objectFace = $cable[$connectorAttributePrefix.'_object_face'];
$objectDepth = $cable[$connectorAttributePrefix.'_object_depth'];
$objectPortID = $cable[$connectorAttributePrefix.'_port_id'];
$query = $qls->SQL->select('*', 'app_object', array('id' => array('=', $objectID)));
$object = $qls->SQL->fetch_assoc($query);
// Ports
$children = buildPorts($objectID, $objectFace, $cable, $connectorAttributePrefix, $qls);
$value = array(
4,
$objectID,
$objectFace,
$objectDepth,
$objectPortID
);
$value = implode('-', $value);
array_unshift($returnArray, array(
'selected' => $value,
'children' => $children
));
// Objects
$children = buildObjectsConnector($object['env_tree_id'], $cable, $connectorAttributePrefix, $qls);
$objectID = $object['parent_id'] > 0 ? $object['parent_id'] : $objectID;
$value = array(
2,
$objectID,
$objectFace,
0,
0
);
$value = implode('-', $value);
array_unshift($returnArray, array(
'selected' => $value,
'children' => $children
));
// Locations
$envObjectID = $object['env_tree_id'];
$query = $qls->SQL->select('*', 'app_env_tree', array('id' => array('=', $envObjectID)));
$envObject = $qls->SQL->fetch_assoc($query);
$envObjectParentID = $envObject['parent'];
while($envObjectParentID != '#'){
$envObjectType = $envObject['type'];
if($envObjectType == 'cabinet') {
$envObjectTypeID = 1;
} else if($envObjectType == 'location' || $envObjectType == 'pod') {
$envObjectTypeID = 0;
}
$children = buildLocation($envObjectParentID, $qls);
$value = array(
$envObjectTypeID,
$envObjectID,
0,
0,
0
);
$value = implode('-', $value);
array_unshift($returnArray, array(
'selected' => $value,
'children' => $children
));
$envObjectID = $envObjectParentID;
$query = $qls->SQL->select('*', 'app_env_tree', array('id' => array('=', $envObjectID)));
$envObject = $qls->SQL->fetch_assoc($query);
$envObjectParentID = $envObject['parent'];
}
$children = buildLocation('#', $qls);
$value = array(
0,
$envObject['id'],
0,
0,
0
);
$value = implode('-', $value);
array_unshift($returnArray, array(
'selected' => $value,
'children' => $children
));
return $returnArray;
}
function buildConnectorFlatPath($cable, $connectorEnd, &$qls){
$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
$query = $qls->SQL->select('*', 'app_object', array('id' => array('=', $objectID)));
$object = $qls->SQL->fetch_assoc($query);
$objectName = $object['name'];
// Partition variables
$compatibilityTable = buildCompatibilityTable($qls);
$partitionCompatibility = $compatibilityTable[$object['template_id']][$objectFace][$objectDepth];
$templateType = $partitionCompatibility['templateType'];
$partitionFunction = $partitionCompatibility['partitionFunction'];
$portLayoutX = $partitionCompatibility['portLayoutX'];
$portLayoutY = $partitionCompatibility['portLayoutY'];
$portTotal = $portLayoutX * $portLayoutY;
$portNameFormat = json_decode($partitionCompatibility['portNameFormat'],true);
$portName = $qls->App->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'];
$query = $qls->SQL->select('*', 'app_object', array('id' => array('=', $parentID)));
$object = $qls->SQL->fetch_assoc($query);
}
$objectString = $object['name'];
//Locations
$locationString = '';
$envNodeID = $object['env_tree_id'];
$rootEnvNode = false;
while(!$rootEnvNode) {
$query = $qls->SQL->select('*', 'app_env_tree', array('id' => array('=', $envNodeID)));
$envNode = $qls->SQL->fetch_assoc($query);
$envNodeID = $envNode['parent'];
$rootEnvNode = $envNodeID == '#' or !$qls->SQL->num_rows($query) ? true : false;
$locationString = $envNode['name'].'.'.$locationString;
}
$flatPath = $locationString.$objectString.$portString;
} else {
$flatPath = 'None';
}
return $flatPath;
}
function buildTrunkFlatPath($objectID, $objectFace, $objectDepth, &$qls){
if(isset($qls->App->peerArray[$objectID][$objectFace][$objectDepth])) {
// Peer variables
$peerRecord = $qls->App->peerArray[$objectID][$objectFace][$objectDepth];
$peerID = $peerRecord['peerID'];
$peerFace = $peerRecord['peerFace'];
$peerDepth = $peerRecord['peerDepth'];
// Peer object variables
$peer = $qls->App->objectArray[$peerID];
$peerName = $peer['name'];
$peerTemplateID = $peer['template_id'];
$peerTemplateType = $qls->App->templateArray[$peerTemplateID]['templateType'];
if($peerRecord['floorplan_peer']) {
$object = $objectArray[$objectID];
$templateID = $object['template_id'];
$face = $objectFace;
$depth = $objectDepth;
} else {
$templateID = $peerTemplateID;
$face = $peerFace;
$depth = $peerDepth;
}
// Partition variables
$partitionCompatibility = $qls->App->compatibilityArray[$templateID][$face][$depth];
$templateType = $partitionCompatibility['templateType'];
$partitionFunction = $partitionCompatibility['partitionFunction'];
$portNameFormat = json_decode($partitionCompatibility['portNameFormat'], true);
$portTotal = $partitionCompatibility['portLayoutX']*$partitionCompatibility['portLayoutY'];
$firstIndex = 0;
$lastIndex = $portTotal - 1;
$firstPortName = $qls->App->generatePortName($portNameFormat, $firstIndex, $portTotal);
$lastPortName = $qls->App->generatePortName($portNameFormat, $lastIndex, $portTotal);
$portRange = $firstPortName.' ‑ '.$lastPortName;
// Port
if($templateType == 'Insert') {
if($partitionFunction == 'Endpoint') {
$portString = $peerName.$portRange;
} else {
$portString = '.'.$peerName.'.'.$portRange;
}
} else {
$portString = '.'.$portRange;
}
// Peer
if($templateType == 'Insert') {
$parentID = $peer['parent_id'];
$query = $qls->SQL->select('*', 'app_object', array('id' => array('=', $parentID)));
$peer = $qls->SQL->fetch_assoc($query);
}
$objectString = $peer['name'];
//Locations
$locationString = '';
$envNodeID = $peer['env_tree_id'];
$rootEnvNode = false;
while(!$rootEnvNode) {
$query = $qls->SQL->select('*', 'app_env_tree', array('id' => array('=', $envNodeID)));
$envNode = $qls->SQL->fetch_assoc($query);
$envNodeID = $envNode['parent'];
$rootEnvNode = $envNodeID == '#' or !$qls->SQL->num_rows($query) ? true : false;
$locationString = $envNode['name'].'.'.$locationString;
}
$flatPath = $locationString.$objectString.$portString;
} else {
$flatPath = 'None';
}
return $flatPath;
}
function buildPath($peer, $peerFace, $peerDepth, $object, $objectFace, $objectDepth, &$qls){
$templateTable = buildTemplateTable($qls);
$peerTemplateType = $templateTable[$peer['template_id']]['templateType'];
$peerTemplateFunction = $templateTable[$peer['template_id']]['templateFunction'];
$returnArray = array();
// Partitions and Inserts
$children = buildPartitions($peer['id'], $peerFace, $object, $objectFace, $objectDepth, $qls);
$value = array(
3,
$peer['id'],
$peerFace,
$peerDepth,
0
);
$value = implode('-', $value);
$queryString = 'template_id = '.$peer['template_id'].' AND side = '.$peerFace.' AND depth = '.$peerDepth;
$query = $qls->SQL->select('*', 'app_object_compatibility', $queryString);
$partitionCompatibility = $qls->SQL->fetch_assoc($query);
$portCount = $partitionCompatibility['portLayoutX']*$partitionCompatibility['portLayoutY'];
$portStart = $partitionCompatibility['portNumber'];
$portEnd = $portStart + ($portCount - 1);
array_unshift($returnArray, array(
'selected' => $value,
'children' => $children
));
// Objects
$children = buildObjects($peer['env_tree_id'], $object, $objectFace, $objectDepth, $qls);
$elementID = $peerTemplateType == 'Insert' ? $peer['parent_id'] : $peer['id'];
$value = array(
2,
$elementID,
$objectFace,
0,
0
);
$value = implode('-', $value);
array_unshift($returnArray, array(
'selected' => $value,
'children' => $children
));
// Locations
$envObjectID = $peer['env_tree_id'];
$query = $qls->SQL->select('*', 'app_env_tree', array('id' => array('=', $envObjectID)));
$envObject = $qls->SQL->fetch_assoc($query);
$envObjectParentID = $envObject['parent'];
while($envObjectParentID != '#'){
$envObjectType = $envObject['type'];
if($envObjectType == 'cabinet') {
$envObjectTypeID = 1;
} else if($envObjectType == 'location' || $envObjectType == 'pod') {
$envObjectTypeID = 0;
}
$children = buildLocation($envObjectParentID, $qls);
$value = array(
$envObjectTypeID,
$envObjectID,
0,
0,
0
);
$value = implode('-', $value);
array_unshift($returnArray, array(
'selected' => $value,
'children' => $children
));
$envObjectID = $envObjectParentID;
$query = $qls->SQL->select('*', 'app_env_tree', array('id' => array('=', $envObjectID)));
$envObject = $qls->SQL->fetch_assoc($query);
$envObjectParentID = $envObject['parent'];
}
$children = buildLocation('#', $qls);
$value = array(
0,
$envObject['id'],
0,
0,
0
);
$value = implode('-', $value);
array_unshift($returnArray, array(
'selected' => $value,
'children' => $children
));
return $returnArray;
}
function isObjectTrunked($id, $face, $depth, &$qls){
$query = $qls->SQL->select('id', 'app_object_peer', '(a_id = '.$id.' AND a_face = '.$face.' AND a_depth = '.$depth.' AND floorplan_peer = 0) OR (b_id = '.$id.' AND b_face = '.$face.' AND b_depth = '.$depth.' AND floorplan_peer = 0)');
return $qls->SQL->num_rows($query);
}
function isObjectTrunkedAndEndpoint($id, $face, $depth, &$qls){
$query = $qls->SQL->select('id', 'app_object_peer', '(a_id = '.$id.' AND a_face = '.$face.' AND a_depth = '.$depth.' AND a_endpoint = True) OR (b_id = '.$id.' AND b_face = '.$face.' AND b_depth = '.$depth.' AND b_endpoint = True)');
return $qls->SQL->num_rows($query);
}
function loopDetected(&$qls, $aID, $aFace, $aDepth, $aPort, $bID, $bFace, $bDepth, $bPort){
// If cable is connected to an object
if($aID != 0) {
$query = $qls->SQL->select('*', 'app_object_peer', '(a_id = '.$aID.' AND a_face = '.$aFace.' AND a_depth = '.$aDepth.') OR (b_id = '.$aID.' AND b_face = '.$aFace.' AND b_depth = '.$aDepth.')');
// If object is trunked
if($qls->SQL->num_rows($query)) {
$peerRecord = $qls->SQL->fetch_assoc($query); // table_object_peer(5)
$peerNearAttr = $peerRecord['a_id'] == $aID ? 'a' : 'b'; // 'b'
$peerFarAttr = $peerRecord['a_id'] == $aID ? 'b' : 'a'; // 'a'
// If object's peer is not an endpoint
if($peerRecord[$peerNearAttr.'_endpoint'] != 1) {
$objID = $peerRecord[$peerFarAttr.'_id']; // 22
$objFace = $peerRecord[$peerFarAttr.'_face']; // 0
$objDepth = $peerRecord[$peerFarAttr.'_depth']; // 0
$query = $qls->SQL->select('*', 'app_inventory', '(a_object_id = '.$objID.' AND a_object_face = '.$objFace.' AND a_object_depth = '.$objDepth.' AND a_port_id = '.$aPort.') OR (b_object_id = '.$objID.' AND b_object_face = '.$objFace.' AND b_object_depth = '.$objDepth.' AND b_port_id = '.$aPort.')');
// If peer has cable connected
if($qls->SQL->num_rows($query)) {
$peerCable = $qls->SQL->fetch_assoc($query);
$connectorAttrPrefix = $peerCable['a_object_id'] == $objID ? 'b' : 'a';
$peerID = $peerCable[$connectorAttrPrefix.'_object_id'];
$peerFace = $peerCable[$connectorAttrPrefix.'_object_face'];
$peerDepth = $peerCable[$connectorAttrPrefix.'_object_depth'];
$peerPort = $peerCable[$connectorAttrPrefix.'_port_id'];
return loopDetected($qls, $peerID, $peerFace, $peerDepth, $peerPort, $objID, $objFace, $objDepth, $aPort);
} else if($objID == $bID and $objFace == $bFace and $objDepth == $bDepth and $aPort == $bPort) {
return true;
} else {
return false;
}
} else {
return false;
}
} else {
return false;
}
} else {
return false;
}
}
function buildPathArray($path){
$pathArray = array();
foreach($path as $pathElement) {
$selected = $pathElement['selected'];
if($selected == '') {
$pathArray = array('-');
} else {
foreach($pathElement['children'] as $child) {
if($child['value'] == $selected) {
array_push($pathArray, $child['text']);
}
}
}
}
return $pathArray;
}
function displayArrow($orientation, $scanned, $code39){
$fill = $scanned ? '#039cfd' : '#ffffff';
$top = '
| '; $htmlPathFull .= displayTrunk(); $htmlPathFull .= ' | '; $htmlPathFull .= '