Ejemplo n.º 1
0
 /**
  * create new section
  */
 public function createSection()
 {
     # verications
     //name must be at least 2 chars
     if (strlen($this->name) < 2) {
         throw new Exception('Invalid section name');
     }
     //strict mode can be blank (default), 1,0
     if (isset($this->strictMode) && !is_numeric($this->strictMode)) {
         throw new Exception('Invalid strict mode parameter');
     }
     //order
     if (isset($this->order) && !is_numeric($this->order)) {
         throw new Exception('Order must be numberic value');
     }
     //check if it already exist
     if (sizeof(getSectionDetailsByName($this->name)) > 0) {
         throw new Exception('Section with this name already exists');
     }
     //create array to write new section
     $newSection = $this->toArray($this);
     //create new section
     $res = UpdateSection($newSection, true);
     //true means from API
     //return result (true/false)
     if (!$res) {
         throw new Exception('Invalid query');
     } else {
         //format response
         return "Section created";
     }
 }
Ejemplo n.º 2
0
/**
 *	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>";
                }
            }
        }
    }
}