Exemple #1
0
/**
 * Print subnets structure
 */
function printToolsSubnets($subnets, $custom)
{
    $html = array();
    $rootId = 0;
    # root is 0
    # remove all not permitted!
    foreach ($subnets as $k => $s) {
        $permission = checkSubnetPermission($s['id']);
        if ($permission == "0") {
            unset($subnets[$k]);
        }
    }
    if (sizeof($subnets) > 0) {
        foreach ($subnets as $item) {
            $children[$item['masterSubnetId']][] = $item;
        }
    }
    # loop will be false if the root has no children (i.e., an empty menu!)
    $loop = !empty($children[$rootId]);
    # initializing $parent as the root
    $parent = $rootId;
    $parent_stack = array();
    # display selected subnet as opened
    if (isset($_GET['subnetId'])) {
        $allParents = getAllParents($_GET['subnetId']);
    }
    # return table content (tr and td's)
    while ($loop && (($option = each($children[$parent])) || $parent > $rootId)) {
        # repeat
        $repeat = str_repeat(" - ", count($parent_stack));
        # dashes
        if (count($parent_stack) == 0) {
            $dash = "";
        } else {
            $dash = "-";
        }
        if (count($parent_stack) == 0) {
            $margin = "0px";
            $padding = "0px";
        } else {
            # padding
            $padding = "10px";
            # margin
            $margin = count($parent_stack) * 10 - 10;
            $margin = $margin * 2;
            $margin = $margin . "px";
        }
        # count levels
        $count = count($parent_stack) + 1;
        # get subnet details
        # get VLAN
        $vlan = subnetGetVLANdetailsById($option['value']['vlanId']);
        $vlan = $vlan['number'];
        if (empty($vlan) || $vlan == "0") {
            $vlan = "";
        }
        # no VLAN
        # description
        if (strlen($option['value']['description']) == 0) {
            $description = "/";
        } else {
            $description = $option['value']['description'];
        }
        # description
        # requests
        if ($option['value']['allowRequests'] == 1) {
            $requests = "<i class='fa fa-gray fa-check'></i>";
        } else {
            $requests = "";
        }
        # request disabled
        # hosts check
        if ($option['value']['pingSubnet'] == 1) {
            $pCheck = "<i class='fa fa-gray fa-check'></i>";
        } else {
            $pCheck = "";
        }
        # ping check disabled
        # print table line
        if (strlen($option['value']['subnet']) > 0) {
            $html[] = "<tr>";
            # folder
            if ($option['value']['isFolder'] == 1) {
                $html[] = "\t<td class='level{$count}'><span class='structure' style='padding-left:{$padding}; margin-left:{$margin};'></span><i class='fa fa-sfolder fa-folder-open'></i> <a href='" . create_link("folder", $option['value']['sectionId'], $option['value']['id']) . "'>{$description}</a></td>";
                $html[] = "\t<td class='level{$count}'><span class='structure' style='padding-left:{$padding}; margin-left:{$margin};'></span><i class='fa fa-sfolder fa-folder-open'></i> {$description}</td>";
            } else {
                if ($count == 1) {
                    $html[] = "\t<td class='level{$count}'><span class='structure' style='padding-left:{$padding}; margin-left:{$margin};'></span><i class='fa fa-gray fa-folder-open-o'></i><a href='" . create_link("subnets", $option['value']['sectionId'], $option['value']['id']) . "'>  " . transform2long($option['value']['subnet']) . "/" . $option['value']['mask'] . "</a></td>";
                    $html[] = "\t<td class='level{$count}'><span class='structure' style='padding-left:{$padding}; margin-left:{$margin};'></span><i class='fa fa-gray fa-folder-open-o'></i> {$description}</td>";
                } else {
                    # last?
                    if (!empty($children[$option['value']['id']])) {
                        $html[] = "\t<td class='level{$count}'><span class='structure' style='padding-left:{$padding}; margin-left:{$margin};'></span><i class='fa fa-folder-open-o'></i><a href='" . create_link("subnets", $option['value']['sectionId'], $option['value']['id']) . "'>  " . transform2long($option['value']['subnet']) . "/" . $option['value']['mask'] . "</a></td>";
                        $html[] = "\t<td class='level{$count}'><span class='structure' style='padding-left:{$padding}; margin-left:{$margin};'></span><i class='fa fa-folder-open-o'></i> {$description}</td>";
                    } else {
                        $html[] = "\t<td class='level{$count}'><span class='structure' style='padding-left:{$padding}; margin-left:{$margin};'></span><i class='fa fa-angle-right'></i><a href='" . create_link("subnets", $option['value']['sectionId'], $option['value']['id']) . "'>  " . transform2long($option['value']['subnet']) . "/" . $option['value']['mask'] . "</a></td>";
                        $html[] = "\t<td class='level{$count}'><span class='structure' style='padding-left:{$padding}; margin-left:{$margin};'></span><i class='fa fa-angle-right'></i> {$description}</td>";
                    }
                }
            }
            //vlan
            $html[] = "\t<td>{$vlan}</td>";
            //masterSubnet
            if ($option['value']['masterSubnetId'] == 0 || empty($option['value']['masterSubnetId'])) {
                $masterSubnet = true;
            } else {
                $masterSubnet = false;
            }
            if ($masterSubnet) {
                $html[] = '	<td>/</td>' . "\n";
            } else {
                $master = getSubnetDetailsById($option['value']['masterSubnetId']);
                if ($master['isFolder']) {
                    $html[] = "\t<td><i class='fa fa-gray fa-folder-open-o'></i> <a href='" . create_link("subnets", $option['value']['sectionId'], $master['id']) . "'>{$master['description']}</a></td>" . "\n";
                } else {
                    $html[] = "\t<td><a href='" . create_link("folder", $option['value']['sectionId'], $master['id']) . "'>" . transform2long($master['subnet']) . '/' . $master['mask'] . '</a></td>' . "\n";
                }
            }
            //used , free
            if ($option['value']['isFolder'] == 1) {
                $html[] = '<td class="hidden-xs hidden-sm"></td>' . "\n";
            } elseif (!$masterSubnet || !subnetContainsSlaves($option['value']['id'])) {
                $ipCount = countIpAddressesBySubnetId($option['value']['id']);
                $calculate = calculateSubnetDetails(gmp_strval($ipCount), $option['value']['mask'], $option['value']['subnet']);
                $html[] = ' <td class="used hidden-xs hidden-sm">' . reformatNumber($calculate['used']) . '/' . reformatNumber($calculate['maxhosts']) . ' (' . reformatNumber($calculate['freehosts_percent']) . ' %)</td>';
            } else {
                $html[] = '<td class="hidden-xs hidden-sm"></td>' . "\n";
            }
            //requests
            $html[] = "\t<td class='hidden-xs hidden-sm'>{$requests}</td>";
            $html[] = "\t<td class='hidden-xs hidden-sm'>{$pCheck}</td>";
            //custom
            if (sizeof($custom) > 0) {
                foreach ($custom as $field) {
                    $html[] = "<td class='hidden-xs hidden-sm hidden-md'>";
                    //booleans
                    if ($field['type'] == "tinyint(1)") {
                        if ($option['value'][$field['name']] == "0") {
                            $html[] = _("No");
                        } elseif ($option['value'][$field['name']] == "1") {
                            $html[] = _("Yes");
                        }
                    } elseif ($field['type'] == "text") {
                        if (strlen($option['value'][$field['name']]) > 0) {
                            $html[] = "<i class='fa fa-gray fa-comment' rel='tooltip' data-container='body' data-html='true' title='" . str_replace("\n", "<br>", $option['value'][$field['name']]) . "'>";
                        } else {
                            $html[] = "";
                        }
                    } else {
                        $html[] = $option['value'][$field['name']];
                    }
                    $html[] = "</td>";
                }
            }
            $html[] = "</tr>";
        }
        if ($option === false) {
            $parent = array_pop($parent_stack);
        } elseif (!empty($children[$option['value']['id']])) {
            array_push($parent_stack, $option['value']['masterSubnetId']);
            $parent = $option['value']['id'];
        } else {
        }
    }
    return implode("\n", $html);
}
/**
 * Print subnets structure
 */
function printAdminSubnets($subnets, $actions = true, $vrf = "0")
{
    $html = array();
    $rootId = 0;
    # root is 0
    if (sizeof($subnets) > 0) {
        foreach ($subnets as $item) {
            $children[$item['masterSubnetId']][] = $item;
        }
    }
    /* get custom fields */
    $custom = getCustomFields('subnets');
    global $settings;
    /* set hidden fields */
    $ffields = json_decode($settings['hiddenCustomFields'], true);
    if (is_array($ffields['subnets'])) {
        $ffields = $ffields['subnets'];
    } else {
        $ffields = array();
    }
    # loop will be false if the root has no children (i.e., an empty menu!)
    $loop = !empty($children[$rootId]);
    # initializing $parent as the root
    $parent = $rootId;
    $parent_stack = array();
    # display selected subnet as opened
    if (isset($_GET['subnetId'])) {
        if (!is_numeric($_GET['subnetId'])) {
            die('<div class="alert alert-danger">' . _("Invalid ID") . '</div>');
        }
        $allParents = getAllParents($_GET['subnetId']);
    }
    # return table content (tr and td's)
    while ($loop && (($option = each($children[$parent])) || $parent > $rootId)) {
        # repeat
        $repeat = str_repeat(" - ", count($parent_stack));
        # dashes
        if (count($parent_stack) == 0) {
            $dash = "";
        } else {
            $dash = "-";
        }
        if (count($parent_stack) == 0) {
            $margin = "0px";
            $padding = "0px";
        } else {
            # padding
            $padding = "10px";
            # margin
            $margin = count($parent_stack) * 10 - 10;
            $margin = $margin * 2;
            $margin = $margin . "px";
        }
        # count levels
        $count = count($parent_stack) + 1;
        # get VLAN
        $vlan = subnetGetVLANdetailsById($option['value']['vlanId']);
        $vlan = $vlan['number'];
        if (empty($vlan) || $vlan == "0") {
            $vlan = "";
        }
        # no VLAN
        # description
        if (strlen($option['value']['description']) == 0) {
            $description = "/";
        } else {
            $description = $option['value']['description'];
        }
        # description
        # requests
        if ($option['value']['allowRequests'] == 1) {
            $requests = "<i class='fa fa-gray fa-check'></i>";
        } else {
            $requests = "";
        }
        # request disabled
        # hosts check
        if ($option['value']['pingSubnet'] == 1) {
            $pCheck = "<i class='fa fa-gray fa-check'></i>";
        } else {
            $pCheck = "";
        }
        # ping check disabled
        #vrf
        if ($vrf == "1") {
            # get VRF details
            if ($option['value']['vrfId'] != "0" && $option['value']['vrfId'] != "NULL") {
                $vrfTmp = getVRFDetailsById($option['value']['vrfId']);
                $vrfText = $vrfTmp['name'];
            } else {
                $vrfText = "";
            }
        }
        # print table line
        if (strlen($option['value']['subnet']) > 0) {
            $html[] = "<tr>";
            # folder
            if ($option['value']['isFolder'] == 1) {
                $html[] = "\t<td class='level{$count}'><span class='structure' style='padding-left:{$padding}; margin-left:{$margin};'></span><i class='fa fa-sfolder fa-folder-open'></i> <a href='" . create_link("folder", $option['value']['sectionId'], $option['value']['id']) . "'>{$description}</a></td>";
                $html[] = "\t<td class='level{$count}'><span class='structure' style='padding-left:{$padding}; margin-left:{$margin};'></span><i class='fa fa-sfolder fa-folder-open'></i> {$description}</td>";
            } else {
                if ($count == 1) {
                    $html[] = "\t<td class='level{$count}'><span class='structure' style='padding-left:{$padding}; margin-left:{$margin};'></span><i class='fa fa-folder-open-o'></i><a href='" . create_link("subnets", $option['value']['sectionId'], $option['value']['id']) . "'>  " . transform2long($option['value']['subnet']) . "/" . $option['value']['mask'] . "</a></td>";
                    $html[] = "\t<td class='level{$count}'><span class='structure' style='padding-left:{$padding}; margin-left:{$margin};'></span><i class='fa fa-folder-open-o'></i> {$description}</td>";
                } else {
                    # last?
                    if (!empty($children[$option['value']['id']])) {
                        $html[] = "\t<td class='level{$count}'><span class='structure' style='padding-left:{$padding}; margin-left:{$margin};'></span><i class='fa fa-folder-open-o'></i> <a href='" . create_link("subnets", $option['value']['sectionId'], $option['value']['id']) . "'>  " . transform2long($option['value']['subnet']) . "/" . $option['value']['mask'] . "</a></td>";
                        $html[] = "\t<td class='level{$count}'><span class='structure' style='padding-left:{$padding}; margin-left:{$margin};'></span><i class='fa fa-folder-open-o'></i> {$description}</td>";
                    } else {
                        $html[] = "\t<td class='level{$count}'><span class='structure' style='padding-left:{$padding}; margin-left:{$margin};'></span><i class='fa fa-angle-right'></i> <a href='" . create_link("subnets", $option['value']['sectionId'], $option['value']['id']) . "'>  " . transform2long($option['value']['subnet']) . "/" . $option['value']['mask'] . "</a></td>";
                        $html[] = "\t<td class='level{$count}'><span class='structure' style='padding-left:{$padding}; margin-left:{$margin};'></span><i class='fa fa-angle-right'></i> {$description}</td>";
                    }
                }
            }
            $html[] = "\t<td class='hidden-xs hidden-sm'>{$vlan}</td>";
            #vrf
            if ($vrf == "1") {
                $html[] = "\t<td class='hidden-xs hidden-sm'>{$vrfText}</td>";
            }
            $html[] = "\t<td class='hidden-xs hidden-sm hidden-md'>{$requests}</td>";
            $html[] = "\t<td class='hidden-xs hidden-sm hidden-md'>{$pCheck}</td>";
            # custom
            if (sizeof($custom) > 0) {
                foreach ($custom as $field) {
                    if (!in_array($field['name'], $ffields)) {
                        $html[] = "\t<td class='hidden-xs hidden-sm'>" . $option['value'][$field['name']] . "</td>";
                    }
                }
            }
            # actions
            if ($actions) {
                $html[] = "\t<td class='actions' style='padding:0px;'>";
                $html[] = "\t<div class='btn-group btn-group-xs'>";
                if ($option['value']['isFolder'] == 1) {
                    $html[] = "\t\t<button class='btn btn-sm btn-default add_folder'     data-action='edit'   data-subnetid='" . $option['value']['id'] . "'  data-sectionid='" . $option['value']['sectionId'] . "'><i class='fa fa-gray fa-pencil'></i></button>";
                    $html[] = "\t\t<button class='btn btn-sm btn-default showSubnetPerm' data-action='show'   data-subnetid='" . $option['value']['id'] . "'  data-sectionid='" . $option['value']['sectionId'] . "'><i class='fa fa-gray fa-tasks'></i></button>";
                    $html[] = "\t\t<button class='btn btn-sm btn-default add_folder'     data-action='delete' data-subnetid='" . $option['value']['id'] . "'  data-sectionid='" . $option['value']['sectionId'] . "'><i class='fa fa-gray fa-times'></i></button>";
                } else {
                    $html[] = "\t\t<button class='btn btn-sm btn-default editSubnet'     data-action='edit'   data-subnetid='" . $option['value']['id'] . "'  data-sectionid='" . $option['value']['sectionId'] . "'><i class='fa fa-gray fa-pencil'></i></button>";
                    $html[] = "\t\t<button class='btn btn-sm btn-default showSubnetPerm' data-action='show'   data-subnetid='" . $option['value']['id'] . "'  data-sectionid='" . $option['value']['sectionId'] . "'><i class='fa fa-gray fa-tasks'></i></button>";
                    $html[] = "\t\t<button class='btn btn-sm btn-default editSubnet'     data-action='delete' data-subnetid='" . $option['value']['id'] . "'  data-sectionid='" . $option['value']['sectionId'] . "'><i class='fa fa-gray fa-times'></i></button>";
                }
                $html[] = "\t</div>";
                $html[] = "\t</td>";
            }
            $html[] = "</tr>";
        }
        if ($option === false) {
            $parent = array_pop($parent_stack);
        } elseif (!empty($children[$option['value']['id']])) {
            array_push($parent_stack, $option['value']['masterSubnetId']);
            $parent = $option['value']['id'];
        } else {
        }
    }
    return implode("\n", $html);
}
/**
 *	print breadcrumbs
 */
function printBreadcrumbs($req)
{
    # subnets
    if (isset($req['ipaddrid'])) {
        if (isset($req['subnetId'])) {
            # get all parents
            $parents = getAllParents($req['subnetId']);
            print "<ul class='breadcrumb'>";
            # remove root - 0
            array_shift($parents);
            # section details
            if (is_numeric($req['section'])) {
                $section = getSectionDetailsById($req['section']);
            } else {
                $section = getSectionDetailsByName($req['section']);
            }
            # if name is provided
            print "\t<li><a href='subnets/{$section['id']}/'>{$section['name']}</a> <span class='divider'></span></li>";
            # section name
            foreach ($parents as $parent) {
                $subnet = getSubnetDetailsById($parent);
                if ($subnet['isFolder'] == 1) {
                    print "\t<li><a href='subnets/{$section['id']}/{$parent}/'><i class='icon-folder-open icon-gray'></i> {$subnet['description']}</a> <span class='divider'></span></li>";
                    # subnets in between
                } else {
                    print "\t<li><a href='subnets/{$section['id']}/{$parent}/'>{$subnet['description']} (" . Transform2long($subnet['subnet']) . '/' . $subnet['mask'] . ")</a> <span class='divider'></span></li>";
                    # subnets in between
                }
            }
            # parent subnet
            $subnet = getSubnetDetailsById($req['subnetId']);
            print "\t<li><a href='subnets/{$section['id']}/{$subnet['id']}/'>{$subnet['description']} (" . Transform2long($subnet['subnet']) . '/' . $subnet['mask'] . ")</a> <span class='divider'></span></li>";
            # active subnet
            # ip
            $ip = getIpAddrDetailsById($req['ipaddrid']);
            print "\t<li class='active'>{$ip['ip_addr']}</li>";
            # IP address
            print "</ul>";
        }
    } elseif ($req['page'] == "subnets") {
        if (isset($req['subnetId'])) {
            # get all parents
            $parents = getAllParents($req['subnetId']);
            print "<ul class='breadcrumb'>";
            # remove root - 0
            array_shift($parents);
            # section details
            if (is_numeric($req['section'])) {
                $section = getSectionDetailsById($req['section']);
            } else {
                $section = getSectionDetailsByName($req['section']);
            }
            # if name is provided
            print "\t<li><a href='subnets/{$section['id']}/'>{$section['name']}</a> <span class='divider'></span></li>";
            # section name
            foreach ($parents as $parent) {
                $subnet = getSubnetDetailsById($parent);
                if ($subnet['isFolder'] == 1) {
                    print "\t<li><a href='subnets/{$section['id']}/{$parent}/'><i class='icon-folder-open icon-gray'></i> {$subnet['description']}</a> <span class='divider'></span></li>";
                    # subnets in between
                } else {
                    print "\t<li><a href='subnets/{$section['id']}/{$parent}/'>{$subnet['description']} (" . Transform2long($subnet['subnet']) . '/' . $subnet['mask'] . ")</a> <span class='divider'></span></li>";
                    # subnets in between
                }
            }
            $subnet = getSubnetDetailsById($req['subnetId']);
            print "\t<li class='active'>{$subnet['description']} (" . Transform2long($subnet['subnet']) . '/' . $subnet['mask'] . ")</li>";
            # active subnet
            print "</ul>";
        }
    }
    # subnets
    if ($req['page'] == "folder") {
        if (isset($req['subnetId'])) {
            # get all parents
            $parents = getAllParents($req['subnetId']);
            print "<ul class='breadcrumb'>";
            # remove root - 0
            array_shift($parents);
            # section details
            if (is_numeric($req['section'])) {
                $section = getSectionDetailsById($req['section']);
            } else {
                $section = getSectionDetailsByName($req['section']);
            }
            # if name is provided
            print "\t<li><a href='subnets/{$section['id']}/'>{$section['name']}</a> <span class='divider'></span></li>";
            # section name
            foreach ($parents as $parent) {
                $subnet = getSubnetDetailsById($parent);
                print "\t<li><a href='subnets/{$section['id']}/{$parent}/'><i class='icon-folder-open icon-gray'></i> {$subnet['description']}</a> <span class='divider'></span></li>";
                # subnets in between
            }
            $subnet = getSubnetDetailsById($req['subnetId']);
            print "\t<li class='active'>{$subnet['description']}</li>";
            # active subnet
            print "</ul>";
        }
    } else {
        if ($req['page'] == "admin") {
        } else {
            if ($req['page'] == "tools") {
                if (isset($req['tpage'])) {
                    print "<ul class='breadcrumb'>";
                    print "\t<li><a href='tools/'>" . _('Tools') . "</a> <span class='divider'></span></li>";
                    print "\t<li class='active'>{$req['tpage']}></li>";
                    print "</ul>";
                }
            }
        }
    }
}
Exemple #4
0
function getDocAndTVVResults($search, $searchOptions)
{
    global $modx;
    // set SQL data selection
    $sqlSelection = "id, pagetitle, longtitle, published, hidemenu, description, alias, introtext, menutitle, content, createdon, editedon";
    // set search fields
    $searchFieldArray = explode(", ", $sqlSelection);
    // search in all defined fields
    $dbTable = $modx->getTableName("modResource");
    foreach ($searchFieldArray as $searchField) {
        // Filter: Check where to search in and where to skip
        if (!$searchOptions['id'] and $searchField == "id") {
            continue;
        }
        if (!$searchOptions['pagetitle'] and $searchField == "pagetitle") {
            continue;
        }
        if (!$searchOptions['longtitle'] and $searchField == "longtitle") {
            continue;
        }
        if (!$searchOptions['description'] and $searchField == "description") {
            continue;
        }
        if (!$searchOptions['alias'] and $searchField == "alias") {
            continue;
        }
        if (!$searchOptions['introtext'] and $searchField == "introtext") {
            continue;
        }
        if (!$searchOptions['menutitle'] and $searchField == "menutitle") {
            continue;
        }
        if (!$searchOptions['content'] and $searchField == "content") {
            continue;
        }
        // Filter: createdon and editedon are not searched directly
        if ($searchField == "createdon" or $searchField == "editedon") {
            continue;
        }
        // get SQL WHERE else continue
        if ($search['string'] != "ALL") {
            $sqlWhere = getSqlWhere($search['string'], $searchField, $searchOptions);
            if (!$sqlWhere) {
                continue;
            }
        }
        // complete SQL query
        $sql = "SELECT {$sqlSelection} FROM {$dbTable} {$sqlWhere}";
        // query DB via MODx DB API
        $result = $modx->query($sql);
        // get rows
        while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
            // check created date range
            if ($row['createdon'] < $searchOptions['createdon_start_time'] or $row['createdon'] > $searchOptions['createdon_end_time']) {
                continue;
            }
            // check edited date range
            if ($row['editedon'] < $searchOptions['editedon_start_time'] or $row['editedon'] > $searchOptions['editedon_end_time']) {
                continue;
            }
            $id = $row['id'];
            // checkParents
            $parents = getAllParents($id);
            if (checkparents($search['parentsArray'], $parents)) {
                // save results in our results array
                $searchResultsArray[$id]['id'] = $id;
                $searchResultsArray[$id]['pagetitle'] = $row['pagetitle'];
                $searchResultsArray[$id]['longtitle'] = $row['longtitle'];
                $searchResultsArray[$id]['createdon'] = $row['createdon'];
                $searchResultsArray[$id]['editedon'] = $row['editedon'];
                $searchResultsArray[$id]['published'] = $row['published'];
                $searchResultsArray[$id]['hidemenu'] = $row['hidemenu'];
                $searchResultsArray[$id]['found_in'] .= ", " . ucfirst($searchField);
                $searchResultsArray[$id]['parentsArray'] = $parents;
                // replace
                if ($searchOptions['replace_mode'] and $searchField != "id") {
                    replace($search['string'], $searchOptions['replace'], $id, $searchField, $row[$searchField], $dbTable);
                }
            }
        }
        // jump to next search array key
        next($search);
    }
    // search in TVs if required
    if ($searchOptions['tvs'] and $search['string'] != "ALL") {
        $tableTV_Names = $modx->getTableName("modTemplateVar");
        $tableTV_Content = $modx->getTableName("modTemplateVarResource");
        // get SQL WHERE
        $sqlWhere = getSqlWhere($search['string'], 'value', $searchOptions);
        // complete SQL query
        $sqlTVNames = "SELECT id, name FROM {$tableTV_Names}";
        $sqlTVContent = "SELECT contentid, value, tmplvarid, id FROM {$tableTV_Content} {$sqlWhere}";
        // query DB via MODx DB API
        $resultTVNames = $modx->query($sqlTVNames);
        $resultTVContent = $modx->query($sqlTVContent);
        // get rows TV names
        while ($row = $resultTVNames->fetch(PDO::FETCH_ASSOC)) {
            $id = $row['id'];
            $name = $row['name'];
            $TV_Names[$id]['id'] = $id;
            $TV_Names[$id]['name'] = $name;
        }
        // get rows TV content
        while ($row = $resultTVContent->fetch(PDO::FETCH_ASSOC)) {
            $id = $row['contentid'];
            // checkParents
            $parents = getAllParents($id);
            if (checkparents($search['parentsArray'], $parents)) {
                $TV_varID = $row['tmplvarid'];
                $TV_ID = $row['id'];
                $document = $modx->getObject('modResource', array('id' => $id));
                // check created date range
                if ($document->get('createdon') < $searchOptions['createdon_start_time'] or $document->get('createdon') > $searchOptions['createdon_end_time']) {
                    continue;
                }
                // check edited date range
                if ($document->get('editedon') < $searchOptions['editedon_start_time'] or $document->get('editedon') > $searchOptions['editedon_end_time']) {
                    continue;
                }
                // save results in our results array
                $searchResultsArray[$id]['id'] = $id;
                $searchResultsArray[$id]['pagetitle'] = $document->get('pagetitle');
                $searchResultsArray[$id]['longtitle'] = $document->get('longtitle');
                $searchResultsArray[$id]['published'] = $document->get('published');
                $searchResultsArray[$id]['hidemenu'] = $document->get('hidemenu');
                $searchResultsArray[$id]['createdon'] = $document->get('createdon');
                $searchResultsArray[$id]['editedon'] = $document->get('editedon');
                $searchResultsArray[$id]['found_in'] .= ", tv_" . $TV_Names[$TV_varID]['name'];
                // replace
                if ($searchOptions['replace_mode'] and $searchField != "id") {
                    replace($search['string'], $searchOptions['replace'], $TV_ID, 'value', $row['value'], $tableTV_Content);
                }
            }
        }
    }
    return $searchResultsArray;
}
/**
 *	Print dropdown menu for folders in section!
 */
function printDropdownMenuBySectionFolders($sectionId, $subnetMasterId = "0")
{
    # get all subnets
    $subnets = fetchFolders($sectionId);
    $html = array();
    $rootId = 0;
    # root is 0
    # must be integer
    if (isset($_GET['subnetId'])) {
        if (!is_numeric($_GET['subnetId'])) {
            die('<div class="alert alert-danger">' . _("Invalid ID") . '</div>');
        }
    }
    foreach ($subnets as $item) {
        $children[$item['masterSubnetId']][] = $item;
    }
    # loop will be false if the root has no children (i.e., an empty menu!)
    $loop = !empty($children[$rootId]);
    # initializing $parent as the root
    $parent = $rootId;
    $parent_stack = array();
    # display selected subnet as opened
    $allParents = getAllParents($_GET['subnetId']);
    # structure
    $html[] = "<select name='masterSubnetId' class='form-control input-w-auto input-sm'>";
    # root
    $html[] = "<option disabled>" . _("Select Master folder") . "</option>";
    $html[] = "<option value='0'>" . _("Root folder") . "</option>";
    # return table content (tr and td's)
    while ($loop && (($option = each($children[$parent])) || $parent > $rootId)) {
        # repeat
        $repeat = str_repeat(" - ", count($parent_stack));
        # dashes
        if (count($parent_stack) == 0) {
            $dash = "";
        } else {
            $dash = $repeat;
        }
        # count levels
        $count = count($parent_stack) + 1;
        # print table line
        if (strlen($option['value']['subnet']) > 0) {
            # selected
            if ($option['value']['id'] == $subnetMasterId) {
                $html[] = "<option value='" . $option['value']['id'] . "' selected='selected'>{$repeat} " . $option['value']['description'] . "</option>";
            } else {
                $html[] = "<option value='" . $option['value']['id'] . "'>{$repeat} " . $option['value']['description'] . "</option>";
            }
        }
        if ($option === false) {
            $parent = array_pop($parent_stack);
        } elseif (!empty($children[$option['value']['id']])) {
            array_push($parent_stack, $option['value']['masterSubnetId']);
            $parent = $option['value']['id'];
        } else {
        }
    }
    $html[] = "</select>";
    print implode("\n", $html);
}
/**
 * Print subnets structure
 */
function printAdminSubnets($subnets, $actions = true, $vrf = "0")
{
    $html = array();
    $rootId = 0;
    # root is 0
    if (sizeof($subnets) > 0) {
        foreach ($subnets as $item) {
            $children[$item['masterSubnetId']][] = $item;
        }
    }
    # loop will be false if the root has no children (i.e., an empty menu!)
    $loop = !empty($children[$rootId]);
    # initializing $parent as the root
    $parent = $rootId;
    $parent_stack = array();
    # display selected subnet as opened
    if (isset($_REQUEST['subnetId'])) {
        $allParents = getAllParents($_REQUEST['subnetId']);
    }
    # return table content (tr and td's)
    while ($loop && (($option = each($children[$parent])) || $parent > $rootId)) {
        # repeat
        $repeat = str_repeat(" - ", count($parent_stack));
        # dashes
        if (count($parent_stack) == 0) {
            $dash = "";
        } else {
            $dash = "-";
        }
        if (count($parent_stack) == 0) {
            $margin = "0px";
            $padding = "0px";
        } else {
            # padding
            $padding = "10px";
            # margin
            $margin = count($parent_stack) * 10 - 10;
            $margin = $margin * 2;
            $margin = $margin . "px";
        }
        # count levels
        $count = count($parent_stack) + 1;
        # get subnet details
        # get VLAN
        $vlan = subnetGetVLANdetailsById($option['value']['vlanId']);
        $vlan = $vlan['number'];
        if (empty($vlan) || $vlan == "0") {
            $vlan = "";
        }
        # no VLAN
        # description
        if (strlen($option['value']['description']) == 0) {
            $description = "/";
        } else {
            $description = $option['value']['description'];
        }
        # description
        # requests
        if ($option['value']['allowRequests'] == 1) {
            $requests = "enabled";
        } else {
            $requests = "";
        }
        # request disabled
        # hosts check
        if ($option['value']['pingSubnet'] == 1) {
            $pCheck = "enabled";
        } else {
            $pCheck = "";
        }
        # ping check disabled
        #vrf
        if ($vrf == "1") {
            # get VRF details
            if ($option['value']['vrfId'] != "0" && $option['value']['vrfId'] != "NULL") {
                $vrfTmp = getVRFDetailsById($option['value']['vrfId']);
                $vrfText = $vrfTmp['name'];
            } else {
                $vrfText = "";
            }
        }
        # print table line
        if (strlen($option['value']['subnet']) > 0) {
            $html[] = "<tr>";
            $html[] = "\t<td class='level{$count}'><span class='structure' style='padding-left:{$padding}; margin-left:{$margin};'></span><a href='subnets/" . $option['value']['sectionId'] . "/" . $option['value']['id'] . "/'>  " . transform2long($option['value']['subnet']) . "/" . $option['value']['mask'] . "</a></td>";
            $html[] = "\t<td class='level{$count}'><span class='structure' style='padding-left:{$padding}; margin-left:{$margin};'></span> {$description}</td>";
            $html[] = "\t<td>{$vlan}</td>";
            #vrf
            if ($vrf == "1") {
                $html[] = "\t<td>{$vrfText}</td>";
            }
            $html[] = "\t<td>{$requests}</td>";
            $html[] = "\t<td>{$pCheck}</td>";
            if ($actions) {
                $html[] = "\t<td class='actions' style='padding:0px;>";
                $html[] = "\t<div class='btn-group'>";
                $html[] = "\t\t<button class='btn btn-small editSubnet'     data-action='edit'   data-subnetid='" . $option['value']['id'] . "'  data-sectionid='" . $option['value']['sectionId'] . "'><i class='icon-gray icon-pencil'></i></button>";
                $html[] = "\t\t<button class='btn btn-small showSubnetPerm' data-action='show'   data-subnetid='" . $option['value']['id'] . "'  data-sectionid='" . $option['value']['sectionId'] . "'><i class='icon-gray icon-tasks'></i></button>";
                $html[] = "\t\t<button class='btn btn-small editSubnet'     data-action='delete' data-subnetid='" . $option['value']['id'] . "'  data-sectionid='" . $option['value']['sectionId'] . "'><i class='icon-gray icon-remove'></i></button>";
                $html[] = "\t</div>";
                $html[] = "\t</td>";
            }
            $html[] = "</tr>";
        }
        if ($option === false) {
            $parent = array_pop($parent_stack);
        } elseif (!empty($children[$option['value']['id']])) {
            array_push($parent_stack, $option['value']['masterSubnetId']);
            $parent = $option['value']['id'];
        } else {
        }
    }
    return implode("\n", $html);
}
/**
 *	Print dropdown menu for subnets in section!
 */
function printDropdownMenuBySection($sectionId, $subnetMasterId = "0")
{
    # get all subnets
    $subnets = fetchSubnets($sectionId);
    $html = array();
    $rootId = 0;
    # root is 0
    foreach ($subnets as $item) {
        $children[$item['masterSubnetId']][] = $item;
    }
    # loop will be false if the root has no children (i.e., an empty menu!)
    $loop = !empty($children[$rootId]);
    # initializing $parent as the root
    $parent = $rootId;
    $parent_stack = array();
    # display selected subnet as opened
    $allParents = getAllParents($_REQUEST['subnetId']);
    # structure
    $html[] = "<select name='masterSubnetId'>";
    # root
    $html[] = "<option disabled>" . _("Select Master subnet") . "</option>";
    $html[] = "<option value='0'>" . _("Root subnet") . "</option>";
    # return table content (tr and td's)
    while ($loop && (($option = each($children[$parent])) || $parent > $rootId)) {
        # repeat
        $repeat = str_repeat(" - ", count($parent_stack));
        # dashes
        if (count($parent_stack) == 0) {
            $dash = "";
        } else {
            $dash = $repeat;
        }
        # count levels
        $count = count($parent_stack) + 1;
        # print table line
        if (strlen($option['value']['subnet']) > 0) {
            # selected
            if ($option['value']['id'] == $subnetMasterId) {
                $html[] = "<option value='" . $option['value']['id'] . "' selected='selected'>{$repeat} " . transform2long($option['value']['subnet']) . "/" . $option['value']['mask'] . " (" . $option['value']['description'] . ")</option>";
            } else {
                $html[] = "<option value='" . $option['value']['id'] . "'>{$repeat} " . transform2long($option['value']['subnet']) . "/" . $option['value']['mask'] . " (" . $option['value']['description'] . ")</option>";
            }
        }
        if ($option === false) {
            $parent = array_pop($parent_stack);
        } elseif (!empty($children[$option['value']['id']])) {
            array_push($parent_stack, $option['value']['masterSubnetId']);
            $parent = $option['value']['id'];
        } else {
        }
    }
    $html[] = "</select>";
    print implode("\n", $html);
}
Exemple #8
0
function getAllPages($id = 0, $sort = 'parent', $dir = 'ASC', $fields = 'pagetitle, id, menutitle, parent, template, menuindex, published')
{
    global $dbase;
    global $table_prefix;
    $tblsc = $dbase . ".`" . $table_prefix . "site_content`";
    $tbldg = $dbase . ".`" . $table_prefix . "document_groups`";
    // modify field names to use sc. table reference
    $fields = 'sc.' . implode(',sc.', preg_replace("/^\\s/i", "", explode(',', $fields)));
    $sort = 'sc.' . implode(',sc.', preg_replace("/^\\s/i", "", explode(',', $sort)));
    $sql = "SELECT DISTINCT {$fields} FROM {$tblsc} sc\n      LEFT JOIN {$tbldg} dg on dg.document = sc.id\n      WHERE sc.published=1 AND sc.deleted=0\n      ORDER BY {$sort} {$dir};";
    $resourceArray = doSql($sql);
    for ($i = 0; $i < @count($resourceArray); $i++) {
        $p = getAllParents($resourceArray[$i]['id']);
        $resourceArray[$i]['parents'] = $p;
    }
    return $resourceArray;
}