Ejemplo n.º 1
0
     $address1 = optional_param('address1', "", PARAM_TEXT);
     $address2 = optional_param('address2', "", PARAM_TEXT);
     $postcode = optional_param('postcode', "", PARAM_TEXT);
     $response = updateNodeLocation($nodeid, $location, $loccountry, $address1, $address2, $postcode);
     break;
 case "deletenode":
     $nodeid = required_param('nodeid', PARAM_ALPHANUMEXT);
     $response = deleteNode($nodeid);
     break;
 case "getnodesbydate":
     $date = required_param('date', PARAM_INT);
     $response = getNodesByDate($date, $start, $max, $o, $s, $style, $status);
     break;
 case "getnodesbyname":
     $name = required_param('name', PARAM_TEXT);
     $response = getNodesByName($name, $start, $max, $o, $s, $style, $status);
     break;
 case "getnodesbytag":
     $tagid = required_param('tagid', PARAM_ALPHANUMEXT);
     $response = getNodesByTag($tagid, $start, $max, $o, $s, $style, $status);
     break;
 case "getnodesbyurl":
     $url = required_param('url', PARAM_URL);
     $response = getNodesByURL($url, $start, $max, $o, $s, $filternodetypes, $style, $status);
     break;
 case "getnodesbyuser":
     $userid = required_param('userid', PARAM_ALPHANUMEXT);
     $query = optional_param('q', "", PARAM_TEXT);
     $connectionfilter = optional_param('filterbyconnection', '', PARAM_ALPHA);
     $response = getNodesByUser($userid, $start, $max, $o, $s, $filternodetypes, $style, $query, $connectionfilter, $status);
     break;
Ejemplo n.º 2
0
/**
 * Run the sql to get the nodes based on the given parameters.
 * @param integer $status, defaults to 0. (0 - active, 1 - reported, 2 - retired)
 */
function getNetworkConnectionNodesByDepth($currentdepth, $depthnodeid, $nextNodes, $labelmatch = 'false', $links, $linkgroup, $direction, $roles, $uniquepath = 'true', $scope, $status = 0, &$message)
{
    global $DB, $USER, $HUB_SQL;
    $allConnections = array();
    $params = array();
    $currentuser = '';
    if (isset($USER->userid)) {
        $currentuser = $USER->userid;
    }
    $depthnodelabel = "";
    if ($depthnodeid != "") {
        if ($labelmatch == 'true') {
            $tempparams = array();
            $tempparams[0] = $depthnodeid;
            $sql = $HUB_SQL->UTILLIB_NODE_NAME_BY_NODEID;
            $resArray = $DB->select($sql, $tempparams);
            $array = array();
            if ($resArray !== false) {
                $count = count($resArray);
                for ($i = 0; $i < $count; $i++) {
                    $array = $resArray[$i];
                    $depthnodelabel = $array['Name'];
                }
            } else {
                return database_error();
            }
        }
    }
    $searchLinkLabels = "";
    $searchLinkLabelsArray = array();
    if ($links != "" && $linkgroup == "") {
        $pieces = explode(",", $links);
        $loopCount = 0;
        foreach ($pieces as $value) {
            $searchLinkLabelsArray[$loopCount] = $value;
            if ($loopCount == 0) {
                $searchLinkLabels .= "?";
            } else {
                $searchLinkLabels .= ",?";
            }
            $loopCount++;
        }
    }
    $searchNodes = "";
    $searchNodeArray = array();
    $loopCount = 0;
    foreach ($nextNodes as $next) {
        $searchNodeArray[$loopCount] = $next;
        if ($loopCount == 0) {
            $searchNodes .= "?";
        } else {
            $searchNodes .= ",?";
        }
        $loopCount++;
    }
    $searchRoles = "";
    $searchRolesArray = array();
    $pieces = explode(",", $roles);
    $loopCount = 0;
    foreach ($pieces as $value) {
        $searchRolesArray[$loopCount] = $value;
        if ($loopCount == 0) {
            $searchRoles .= "?";
        } else {
            $searchRoles .= ",?";
        }
        $loopCount++;
    }
    $message .= ":searchNodes=" . $searchNodes;
    $message .= ":linkgroup=" . $linkgroup;
    $message .= ":linklabels=" . $links;
    $message .= ":roles=" . $roles;
    $message .= ":direction=" . $direction;
    if ($searchNodes != "") {
        $qry = $HUB_SQL->UTILLIB_NETWORK_CONNECTIONS_BY_DEPTH_SELECT;
        // Add Node / Node Type Matching
        if ($depthnodeid != "") {
            if ($labelmatch == 'true') {
                if ($direction == "outgoing") {
                    $param[count($param)] = $depthnodelabel;
                    $qry .= $HUB_SQL->UTILLIB_NETWORK_CONNECTIONS_BY_DEPTH_TO_LABEL . $HUB_SQL->AND;
                } else {
                    if ($direction == "incoming") {
                        $param[count($param)] = $depthnodelabel;
                        $qry .= $HUB_SQL->UTILLIB_NETWORK_CONNECTIONS_BY_DEPTH_FROM_LABEL . $HUB_SQL->AND;
                    } else {
                        if ($direction == "both") {
                            $param[count($param)] = $depthnodelabel;
                            $param[count($param)] = $depthnodelabel;
                            $qry .= $HUB_SQL->OPENING_BRACKET;
                            $qry .= $HUB_SQL->UTILLIB_NETWORK_CONNECTIONS_BY_DEPTH_TO_LABEL;
                            $qry .= $HUB_SQL->OR;
                            $qry .= $HUB_SQL->UTILLIB_NETWORK_CONNECTIONS_BY_DEPTH_FROM_LABEL;
                            $sqy .= $HUB_SQL->CLOSING_BRACKET . $HUB_SQL->AND;
                        }
                    }
                }
            } else {
                if ($direction == "outgoing") {
                    $param[count($param)] = $depthnodeid;
                    $qry .= $HUB_SQL->UTILLIB_NETWORK_CONNECTIONS_BY_DEPTH_TO_ID . $HUB_SQL->AND;
                } else {
                    if ($direction == "incoming") {
                        $param[count($param)] = $depthnodeid;
                        $qry .= $HUB_SQL->UTILLIB_NETWORK_CONNECTIONS_BY_DEPTH_FROM_ID . $HUB_SQL->AND;
                    } else {
                        if ($direction == "both") {
                            $param[count($param)] = $depthnodeid;
                            $param[count($param)] = $depthnodeid;
                            $qry .= $HUB_SQL->OPENING_BRACKET;
                            $qry .= $HUB_SQL->UTILLIB_NETWORK_CONNECTIONS_BY_DEPTH_TO_ID;
                            $qry .= $HUB_SQL->OR;
                            $qry .= $HUB_SQL->UTILLIB_NETWORK_CONNECTIONS_BY_DEPTH_FROM_ID;
                            $sqy .= $HUB_SQL->CLOSING_BRACKET . $HUB_SQL->AND;
                        }
                    }
                }
            }
        } else {
            if ($roles != "") {
                $nodetypes[$currentdepth - 1] = $searchRoles;
                if ($searchRoles != "") {
                    if ($direction == "outgoing") {
                        $params = array_merge($params, $searchRolesArray);
                        $qry .= $HUB_SQL->UTILLIB_NETWORK_CONNECTIONS_BY_DEPTH_ROLE_TO_PART1 . $searchRoles . $HUB_SQL->UTILLIB_NETWORK_CONNECTIONS_BY_DEPTH_ROLE_TO_PART2 . $HUB_SQL->AND;
                    } else {
                        if ($direction == "incoming") {
                            $params = array_merge($params, $searchRolesArray);
                            $qry .= $HUB_SQL->UTILLIB_NETWORK_CONNECTIONS_BY_DEPTH_ROLE_FROM_PART1 . $searchRoles . $HUB_SQL->UTILLIB_NETWORK_CONNECTIONS_BY_DEPTH_ROLE_FROM_PART2 . $HUB_SQL->AND;
                        } else {
                            if ($direction == "both") {
                                if ($currentdepth == 1) {
                                    if ($labelmatch == 'true') {
                                        $focalnodelabel = $nextNodes[0];
                                        $nodesSet = getNodesByName($focalnodelabel, 0, -1);
                                        $nodes = $nodesSet->nodes;
                                        $rolenames = "";
                                        $rolenamesArray = array();
                                        $rolenamescheck = array();
                                        $loopCount = 0;
                                        foreach ($nodes as $node) {
                                            if (isset($node->role->name)) {
                                                if (!in_array($node->role->name, $rolenamescheck)) {
                                                    $rolenamesArray[$loopCount] = $node->role->name;
                                                    if ($loopCount == 0) {
                                                        $rolenames .= "?";
                                                    } else {
                                                        $rolenames .= ",?";
                                                    }
                                                    $loopCount++;
                                                    array_push($rolenamescheck, $node->role->name);
                                                }
                                            }
                                        }
                                        $message .= ":previousroles=" . $rolenames;
                                        $qry .= $HUB_SQL->UTILLIB_NETWORK_CONNECTIONS_BY_DEPTH_ROLE_BOTH_LABELMATCH_PART1;
                                        $params = array_merge($params, $searchRolesArray);
                                        $qry .= $searchRoles;
                                        $qry .= $HUB_SQL->UTILLIB_NETWORK_CONNECTIONS_BY_DEPTH_ROLE_BOTH_LABELMATCH_PART2;
                                        $params = array_merge($params, $rolenamesArray);
                                        $qry .= $rolenames;
                                        $qry .= $HUB_SQL->UTILLIB_NETWORK_CONNECTIONS_BY_DEPTH_ROLE_BOTH_LABELMATCH_PART3;
                                        $params = array_merge($params, $searchRolesArray);
                                        $qry .= $searchRoles;
                                        $qry .= $HUB_SQL->UTILLIB_NETWORK_CONNECTIONS_BY_DEPTH_ROLE_BOTH_LABELMATCH_PART4;
                                        $params = array_merge($params, $rolenamesArray);
                                        $qry .= $rolenames;
                                        $qry .= $HUB_SQL->UTILLIB_NETWORK_CONNECTIONS_BY_DEPTH_ROLE_BOTH_LABELMATCH_PART5 . $HUB_SQL->AND;
                                    } else {
                                        $focalnodeid = $nextNodes[0];
                                        $node = getNode($focalnodeid);
                                        $rolename = $node->role->name;
                                        $message .= ":previousrole=" . $rolename . "";
                                        $qry .= $HUB_SQL->UTILLIB_NETWORK_CONNECTIONS_BY_DEPTH_ROLE_BOTH_ONE_PART1;
                                        $params = array_merge($params, $searchRolesArray);
                                        $qry .= $searchRoles;
                                        $params[count($params)] = $rolename;
                                        $qry .= $HUB_SQL->UTILLIB_NETWORK_CONNECTIONS_BY_DEPTH_ROLE_BOTH_ONE_PART2;
                                        $params = array_merge($params, $searchRolesArray);
                                        $qry .= $searchRoles;
                                        $params[count($params)] = $rolename;
                                        $qry .= $HUB_SQL->UTILLIB_NETWORK_CONNECTIONS_BY_DEPTH_ROLE_BOTH_ONE_PART3 . $HUB_SQL->AND;
                                    }
                                } else {
                                    if ($currentdepth > 1) {
                                        $previousnodetypes = $nodetypes[$currentdepth - 2];
                                        $previousSearchRoles = "";
                                        $previousSearchRolesArray = array();
                                        $pieces = explode(",", $previousnodetypes);
                                        $loopCount = 0;
                                        foreach ($pieces as $value) {
                                            $previousSearchRolesArray[$loopCount] = $value;
                                            if ($loopCount == 0) {
                                                $previousSearchRoles .= "?";
                                            } else {
                                                $previousSearchRoles .= ",?";
                                            }
                                            $loopCount++;
                                        }
                                        $message .= ":previousnodetype=" . $previousnodetypes;
                                        if ($previousnodetypes != "") {
                                            $qry .= $HUB_SQL->UTILLIB_NETWORK_CONNECTIONS_BY_DEPTH_ROLE_BOTH_PART1;
                                            $params = array_merge($params, $searchRolesArray);
                                            $qry .= $searchRoles;
                                            $qry .= $HUB_SQL->UTILLIB_NETWORK_CONNECTIONS_BY_DEPTH_ROLE_BOTH_PART2;
                                            $params = array_merge($params, $previousSearchRolesArray);
                                            $qry .= $previousSearchRoles;
                                            $qry .= $HUB_SQL->UTILLIB_NETWORK_CONNECTIONS_BY_DEPTH_ROLE_BOTH_PART3;
                                            $params = array_merge($params, $searchRolesArray);
                                            $qry .= $searchRoles;
                                            $qry .= $HUB_SQL->UTILLIB_NETWORK_CONNECTIONS_BY_DEPTH_ROLE_BOTH_PART4;
                                            $params = array_merge($params, $previousSearchRolesArray);
                                            $qry .= $previousSearchRoles;
                                            $qry .= $HUB_SQL->UTILLIB_NETWORK_CONNECTIONS_BY_DEPTH_ROLE_BOTH_PART5 . $HUB_SQL->AND;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        // Add the node matching
        if ($labelmatch == 'true') {
            if ($direction == "outgoing") {
                $params = array_merge($params, $searchNodeArray);
                $qry .= $HUB_SQL->UTILLIB_NETWORK_CONNECTIONS_NODE_FROM_PART1 . $searchNodes . $HUB_SQL->UTILLIB_NETWORK_CONNECTIONS_NODE_FROM_PART2 . $HUB_SQL->AND;
            } else {
                if ($direction == "incoming") {
                    $params = array_merge($params, $searchNodeArray);
                    $qry .= $HUB_SQL->UTILLIB_NETWORK_CONNECTIONS_NODE_TO_PART1 . $searchNodes . $HUB_SQL->UTILLIB_NETWORK_CONNECTIONS_NODE_TO_PART2 . $HUB_SQL->AND;
                } else {
                    if ($direction == "both") {
                        $params = array_merge($params, $searchNodeArray);
                        $qry .= $HUB_SQL->OPENING_BRACKET;
                        $qry .= $HUB_SQL->UTILLIB_NETWORK_CONNECTIONS_NODE_FROM_PART1 . $searchNodes . $HUB_SQL->UTILLIB_NETWORK_CONNECTIONS_NODE_FROM_PART2;
                        $qry .= $HUB_SQL->OR;
                        $params = array_merge($params, $searchNodeArray);
                        $qry .= $HUB_SQL->UTILLIB_NETWORK_CONNECTIONS_NODE_TO_PART1 . $searchNodes . $HUB_SQL->UTILLIB_NETWORK_CONNECTIONS_NODE_TO_PART2;
                        $qry .= $HUB_SQL->CLOSING_BRACKET . $HUB_SQL->AND;
                    }
                }
            }
        } else {
            if ($direction == "outgoing") {
                $params = array_merge($params, $searchNodeArray);
                $qry .= $HUB_SQL->UTILLIB_NETWORK_CONNECTIONS_NODE_FROMID_PART1 . $searchNodes . $HUB_SQL->UTILLIB_NETWORK_CONNECTIONS_NODE_FROMID_PART2 . $HUB_SQL->AND;
            } else {
                if ($direction == "incoming") {
                    $params = array_merge($params, $searchNodeArray);
                    $qry .= $HUB_SQL->UTILLIB_NETWORK_CONNECTIONS_NODE_TOID_PART1 . $searchNodes . $HUB_SQL->UTILLIB_NETWORK_CONNECTIONS_NODE_TOID_PART2 . $HUB_SQL->AND;
                } else {
                    if ($direction == "both") {
                        $params = array_merge($params, $searchNodeArray);
                        $qry .= $HUB_SQL->OPENING_BRACKET;
                        $qry .= $HUB_SQL->UTILLIB_NETWORK_CONNECTIONS_NODE_FROMID_PART1 . $searchNodes . $HUB_SQL->UTILLIB_NETWORK_CONNECTIONS_NODE_FROMID_PART2;
                        $qry .= $HUB_SQL->OR;
                        $params = array_merge($params, $searchNodeArray);
                        $qry .= $HUB_SQL->UTILLIB_NETWORK_CONNECTIONS_NODE_TOID_PART1 . $searchNodes . $HUB_SQL->UTILLIB_NETWORK_CONNECTIONS_NODE_TOID_PART2;
                        $qry .= $HUB_SQL->CLOSING_BRACKET . $HUB_SQL->AND;
                    }
                }
            }
        }
        /** Add the link matching **/
        if ($linkgroup != "" && $linkgroup != "All") {
            $params[count($params)] = $linkgroup;
            $qry .= $HUB_SQL->UTILLIB_NETWORK_CONNECTIONS_LINKGROUP . $HUB_SQL->AND;
        } else {
            if ($links != "") {
                $params = array_merge($params, $searchLinkLabelsArray);
                $qry .= $HUB_SQL->UTILLIB_NETWORK_CONNECTIONS_LINKLABEL_PART1 . $searchLinkLabels . $HUB_SQL->UTILLIB_NETWORK_CONNECTIONS_LINKLABEL_PART2 . $HUB_SQL->AND;
            }
        }
        /** Add the privacy / user permissions **/
        if ($scope == "my") {
            $params[count($params)] = $currentuser;
            $qry .= $HUB_SQL->FILTER_USER;
        } else {
            $params[count($params)] = 'N';
            $params[count($params)] = $currentuser;
            $params[count($params)] = $currentuser;
            $params[count($params)] = 'N';
            $params[count($params)] = $currentuser;
            $params[count($params)] = $currentuser;
            $qry .= $HUB_SQL->APILIB_CONNECTIONS_BY_GLOBAL_PERMISSIONS_NODES;
        }
        // FILTER STATUS
        $params[count($params)] = $status;
        $qry .= $HUB_SQL->AND . $HUB_SQL->APILIB_FILTER_STATUS;
        $qry .= $HUB_SQL->UTILLIB_NETWORK_CONNECTIONS_BY_DEPTH_ORDER_BY;
        /*if ($currentdepth == 2) {
        			$myFile = $CFG->dirAddress."MICHELLE1.txt";
        			$fh = fopen($myFile, 'w') or die("can't open file");
        			$stringData = $qry;
        			fwrite($fh, $stringData);
        			fclose($fh);
        		}*/
        $message .= ":" . $qry;
        //error_log(print_r($params, true));
        //error_log(print_r($qry, true));
        $allConnections = $DB->select($qry, $params);
        if ($allConnections === false) {
            return database_error();
        }
    }
    return $allConnections;
}