Exemplo n.º 1
0
function checkActive($from)
{
    if (getNodeByNid($from)['isActive'] == "yes") {
        return true;
    } else {
        return false;
    }
}
Exemplo n.º 2
0
function deleteEdge($nid1, $nid2)
{
    $result1 = getNodeByNid($nid1);
    $result2 = getNodeByNid($nid2);
    if ($result1['isConnector'] + $result2['isConnector'] == 3) {
        return "failed";
    } else {
        $list = array();
        //first delete edge from two nodes
        deleteEdgeBetweenNodes($nid1, $nid2);
        deleteEdgeBetweenNodes($nid2, $nid1);
        //send message from node1 to node2 to check if msg can be sent
        if (count(sendMessageIgnoreInactive($nid1, $nid2, $list)) == 0) {
            addEdgeBetweenNodes($nid1, $nid2);
            return "failed";
        } else {
            return "success";
        }
    }
}
Exemplo n.º 3
0
<?php

/**
 * Created by PhpStorm.
 * User: Liu
 * Date: 2016/3/1
 * Time: 21:27
 */
include_once "../dao/getNode.php";
$nid = $_POST['nid'];
updateIsActiveToYesByNid($nid);
echo json_encode(getNodeByNid($nid));
Exemplo n.º 4
0
        } else {
            header("location:Main.php?errorMessage=" . $returnMessage);
        }
    } else {
        header("location:Main.php?errorMessage=some value is empty");
    }
}
$nodeResult = getAllNodes();
$linkResult = getAllLinks();
$linkPair = array();
while ($row = mysql_fetch_array($linkResult)) {
    $tempLinkPair = array();
    $x1 = getNodeByNid($row['nid1'])['X'];
    $y1 = getNodeByNid($row['nid1'])['Y'];
    $x2 = getNodeByNid($row['nid2'])['X'];
    $y2 = getNodeByNid($row['nid2'])['Y'];
    $tempLinkPair[0] = $x1;
    $tempLinkPair[1] = $y1;
    $tempLinkPair[2] = $x2;
    $tempLinkPair[3] = $y2;
    array_push($linkPair, $tempLinkPair);
}
?>

<!DOCTYPE>
<html>

<body>
<div align="center">
<canvas id="myCanvas" width="1000" height="1000"></canvas>
</div>
<?php

/**
 * Created by PhpStorm.
 * User: Liu
 * Date: 2016/3/10
 * Time: 15:20
 */
include_once "../dao/getNode.php";
include_once "../dao/getLink.php";
$nid = $_POST['nid'];
$startNid = $_POST['from'];
$node = getNodeByNid($nid);
if ($node == null || $node == array()) {
    echo "inactive";
} else {
    $result = getInactiveNodes();
    $list = array();
    while ($row = mysql_fetch_array($result)) {
        array_push($list, $row['nid']);
    }
    if (in_array($nid, $list)) {
        echo "inactive";
    } else {
        if ($nid != $startNid) {
            if (linkExists($startNid, $nid)) {
                echo "active";
            } else {
                echo "inactive";
            }
        } else {
Exemplo n.º 6
0
function delete($nid)
{
    $row = getNodeByNid($nid);
    // $row['isActive']="no";
    //delete the whole pattern
    $list = array();
    $list[0] = $row['nid'];
    iniRecordList($list);
    if ($row['isConnector'] == 2) {
        return "domainFail";
    } else {
        if ($row['isConnector'] == 1) {
            if (countPatternNodes($row['pid']) > 1) {
                return "patternFail";
            }
            $neighbourList = findNodeNeighbour($row['nid']);
            $did = getDidByNid($nid);
            $domainId = getDomainByDid($did)['nid'];
            if (count($neighbourList) > 1) {
                for ($i = 0; $i < count($neighbourList); $i++) {
                    if ($neighbourList[$i] != $domainId) {
                        if (count(sendMessageIgnoreInactive($neighbourList[$i], $domainId, $list)) == 0) {
                            return "fail";
                        }
                    }
                }
                deleteNodesByNid($row['nid']);
                deleteLinksByNid($row['nid']);
                return "connectorSuccess";
            } else {
                //get all neighbors of this domain, includes one connector node
                $tempDid = $neighbourList[0];
                //echo "did ".$tempDid."</br>";
                $tempNeighbourList = findNodeNeighbour($tempDid);
                $tempCount = 0;
                for ($i = 0; $i < count($tempNeighbourList); $i++) {
                    $tempNode = $tempNeighbourList[$i];
                    if ($tempDid == getDidByNid($tempNode)) {
                        $tempCount++;
                    }
                }
                //echo "count ".$tempCount;
                if ($tempCount >= 1) {
                    deleteNodesByNid($row['nid']);
                    deleteLinksByNid($row['nid']);
                    return "connectorSuccess";
                } else {
                    $domainNeighborList = findNodeNeighbour($domainId);
                    $domainNeighborsCount = count($domainNeighborList);
                    if ($domainNeighborsCount >= 2) {
                        $list[0] = $domainId;
                        iniRecordList($list);
                        for ($i = 0; $i < $domainNeighborsCount; $i++) {
                            for ($j = 0; $j < $domainNeighborsCount; $j++) {
                                if ($domainNeighborList[$i] != $domainNeighborList[$j]) {
                                    if (count(sendMessageIgnoreInactive($domainNeighborList[$i], $domainNeighborList[$j], $list)) == 0) {
                                        return "fail";
                                    }
                                }
                            }
                        }
                    }
                    deleteNodesByNid($domainId);
                    deleteLinksByNid($domainId);
                    deleteNodesByNid($row['nid']);
                    deleteLinksByNid($row['nid']);
                    return $domainId;
                }
            }
        } else {
            $neighbourList = findNodeNeighbour($row['nid']);
            $pid = getPidByNid($nid);
            //  echo $pid;
            $connectorId = getConnectorByPid($pid)['nid'];
            // echo $connectorId;
            for ($i = 0; $i < count($neighbourList); $i++) {
                // echo $neighbourList[$i];
                if ($neighbourList[$i] == $connectorId) {
                } else {
                    if (count(sendMessageIgnoreInactive($neighbourList[$i], $connectorId, $list)) == 0) {
                        return "fail";
                    }
                }
            }
            deleteLinksByNid($row['nid']);
            deleteNodesByNid($row['nid']);
            return "normalSuccess";
        }
    }
}
Exemplo n.º 7
0
     echo "You need to connect to at least one node\n";
     $flag = false;
 }
 if (count($nodes0) == 0) {
     echo "You need to connect to at least one node\n";
     $flag = false;
 }
 if (count($nodes0) > 3) {
     echo "Please select at most three nodes\n";
     $flag = false;
 }
 foreach ($nodes0 as $key => $value) {
     if (getNodeByNid($value)['isConnector'] == 1) {
         $links = getLinksArrayByNid($value);
         foreach ($links as $key1 => $value1) {
             if (getNodeByNid($value1)['isConnector'] == 1 || getNodeByNid($value1)['isConnector'] == 2) {
                 unset($links[$key1]);
             }
         }
         if (count($links) >= 3) {
             echo "Can not connect to Node" . $value . " because it is already connected with three nodes\n";
             $flag = false;
             break;
         }
     } else {
         if (getLinkCountByNid($value) >= 3) {
             echo "Can not connect to Node" . $value . " because it is already connected with three nodes\n";
             $flag = false;
             break;
         }
     }