Beispiel #1
0
function editUserProperties()
{
    $taglist = genericAssertion('taglist', 'array0');
    $user_id = getBypassValue();
    rebuildTagChainForEntity('user', $user_id, buildTagChainFromIds($taglist), TRUE);
    $user = spotEntity('user', $user_id);
    print_r($user);
    showFuncMessage(__FUNCTION__, 'OK', array($user['user_name']));
}
Beispiel #2
0
function produceTagsForNewRecord($realm, $tagidlist, $record_id)
{
    foreach (getExplicitTagsOnly(buildTagChainFromIds($tagidlist)) as $taginfo) {
        addTagForEntity($realm, $record_id, $taginfo['id']);
    }
}
Beispiel #3
0
function renderCellFilterPortlet($preselect, $realm, $cell_list = array(), $bypass_params = array())
{
    addJS('js/tag-cb.js');
    addJS('tag_cb.enableNegation()', TRUE);
    global $pageno, $tabno, $taglist, $tagtree;
    $filterc = count($preselect['tagidlist']) + count($preselect['pnamelist']) + (mb_strlen($preselect['extratext']) ? 1 : 0);
    $title = $filterc ? "Tag filters ({$filterc})" : 'Tag filters';
    startPortlet($title);
    echo "<form method=get>\n";
    echo '<table border=0 align=center cellspacing=0 class="tagtree">';
    $ruler = "<tr><td colspan=2 class=tagbox><hr></td></tr>\n";
    $hr = '';
    // "reset filter" button only gets active when a filter is applied
    $enable_reset = FALSE;
    // "apply filter" button only gets active when there are checkbox/textarea inputs on the roster
    $enable_apply = FALSE;
    // and/or block
    if (getConfigVar('FILTER_SUGGEST_ANDOR') == 'yes' or strlen($preselect['andor'])) {
        echo $hr;
        $hr = $ruler;
        $andor = strlen($preselect['andor']) ? $preselect['andor'] : getConfigVar('FILTER_DEFAULT_ANDOR');
        echo '<tr>';
        foreach (array('and', 'or') as $boolop) {
            $class = 'tagbox' . ($andor == $boolop ? ' selected' : '');
            $checked = $andor == $boolop ? ' checked' : '';
            echo "<td class='{$class}'><label><input type=radio name=andor value={$boolop}";
            echo $checked . ">{$boolop}</input></label></td>";
        }
    }
    $negated_chain = array();
    foreach ($preselect['negatedlist'] as $key) {
        $negated_chain[] = array('id' => $key);
    }
    // tags block
    if (getConfigVar('FILTER_SUGGEST_TAGS') == 'yes' or count($preselect['tagidlist'])) {
        if (count($preselect['tagidlist'])) {
            $enable_reset = TRUE;
        }
        echo $hr;
        $hr = $ruler;
        // Show a tree of tags, pre-select according to currently requested list filter.
        $objectivetags = getShrinkedTagTree($cell_list, $realm, $preselect);
        if (!count($objectivetags)) {
            echo "<tr><td colspan=2 class='tagbox sparenetwork'>(nothing is tagged yet)</td></tr>";
        } else {
            $enable_apply = TRUE;
            printTagCheckboxTable('cft', buildTagChainFromIds($preselect['tagidlist']), $negated_chain, $objectivetags, $realm);
        }
        if (getConfigVar('SHRINK_TAG_TREE_ON_CLICK') == 'yes') {
            addJS('tag_cb.enableSubmitOnClick()', TRUE);
        }
    }
    // predicates block
    if (getConfigVar('FILTER_SUGGEST_PREDICATES') == 'yes' or count($preselect['pnamelist'])) {
        if (count($preselect['pnamelist'])) {
            $enable_reset = TRUE;
        }
        echo $hr;
        $hr = $ruler;
        global $pTable;
        $myPredicates = array();
        $psieve = getConfigVar('FILTER_PREDICATE_SIEVE');
        // Repack matching predicates in a way that tagOnChain() understands.
        foreach (array_keys($pTable) as $pname) {
            if (preg_match("/{$psieve}/", $pname)) {
                $myPredicates[] = array('id' => $pname, 'tag' => $pname);
            }
        }
        if (!count($myPredicates)) {
            echo "<tr><td colspan=2 class='tagbox sparenetwork'>(no predicates to show)</td></tr>";
        } else {
            $enable_apply = TRUE;
            // Repack preselect likewise.
            $myPreselect = array();
            foreach ($preselect['pnamelist'] as $pname) {
                $myPreselect[] = array('id' => $pname);
            }
            printTagCheckboxTable('cfp', $myPreselect, $negated_chain, $myPredicates);
        }
    }
    // extra code
    $enable_textify = FALSE;
    if (getConfigVar('FILTER_SUGGEST_EXTRA') == 'yes' or strlen($preselect['extratext'])) {
        $enable_textify = !empty($preselect['text']) || !empty($preselect['extratext']);
        $enable_apply = TRUE;
        if (strlen($preselect['extratext'])) {
            $enable_reset = TRUE;
        }
        echo $hr;
        $hr = $ruler;
        $class = isset($preselect['extraclass']) ? 'class=' . $preselect['extraclass'] : '';
        echo "<tr><td colspan=2><textarea name=cfe {$class}>\n" . $preselect['extratext'];
        echo "</textarea></td></tr>\n";
    }
    echo $hr;
    $hr = $ruler;
    echo '<tr><td class=tdleft>';
    // "apply"
    echo "<input type=hidden name=page value={$pageno}>\n";
    echo "<input type=hidden name=tab value={$tabno}>\n";
    foreach ($bypass_params as $bypass_name => $bypass_value) {
        echo '<input type=hidden name="' . htmlspecialchars($bypass_name, ENT_QUOTES) . '" value="' . htmlspecialchars($bypass_value, ENT_QUOTES) . '">' . "\n";
    }
    // FIXME: The user will be able to "submit" the empty form even without a "submit"
    // input. To make things consistent, it is necessary to avoid pritning both <FORM>
    // and "and/or" radio-buttons, when enable_apply isn't TRUE.
    if (!$enable_apply) {
        printImageHREF('setfilter gray');
    } else {
        printImageHREF('setfilter', 'set filter', TRUE);
    }
    echo '</form>';
    if ($enable_textify) {
        $text = empty($preselect['text']) || empty($preselect['extratext']) ? $preselect['text'] : '(' . $preselect['text'] . ')';
        $text .= !empty($preselect['extratext']) && !empty($preselect['text']) ? ' ' . $preselect['andor'] . ' ' : '';
        $text .= empty($preselect['text']) || empty($preselect['extratext']) ? $preselect['extratext'] : '(' . $preselect['extratext'] . ')';
        $text = addslashes($text);
        echo " <a href=\"#\" onclick=\"textifyCellFilter(this, '{$text}'); return false\">";
        printImageHREF('COPY', 'Make text expression from current filter');
        echo '</a>';
        addJS(<<<END
function textifyCellFilter(target, text)
{
\tvar portlet = \$(target).closest ('.portlet');
\tportlet.find ('textarea[name="cfe"]').html (text);
\tportlet.find ('input[type="checkbox"]').attr('checked', '');
\tportlet.find ('input[type="radio"][value="and"]').attr('checked','true');
}
END
, TRUE);
    }
    echo '</td><td class=tdright>';
    // "reset"
    if (!$enable_reset) {
        printImageHREF('resetfilter gray');
    } else {
        echo "<form method=get>\n";
        echo "<input type=hidden name=page value={$pageno}>\n";
        echo "<input type=hidden name=tab value={$tabno}>\n";
        echo "<input type=hidden name='cft[]' value=''>\n";
        echo "<input type=hidden name='cfp[]' value=''>\n";
        echo "<input type=hidden name='nft[]' value=''>\n";
        echo "<input type=hidden name='nfp[]' value=''>\n";
        echo "<input type=hidden name='cfe' value=''>\n";
        foreach ($bypass_params as $bypass_name => $bypass_value) {
            echo '<input type=hidden name="' . htmlspecialchars($bypass_name, ENT_QUOTES) . '" value="' . htmlspecialchars($bypass_value, ENT_QUOTES) . '">' . "\n";
        }
        printImageHREF('resetfilter', 'reset filter', TRUE);
        echo '</form>';
    }
    echo '</td></tr>';
    echo '</table>';
    finishPortlet();
}
Beispiel #4
0
Datei: api.php Projekt: xtha/salt
     $dbxlink->commit();
     // redirect to the get_object URL for the edited object
     redirectUser($_SERVER['SCRIPT_NAME'] . "?method=get_object&object_id={$object_id}");
     break;
     // update user-defined tags for an object
     //    UI equivalent: /index.php?module=redirect&page=object&tab=tags&op=saveTags
     //    UI handler: saveEntityTags()
 // update user-defined tags for an object
 //    UI equivalent: /index.php?module=redirect&page=object&tab=tags&op=saveTags
 //    UI handler: saveEntityTags()
 case 'update_object_tags':
     require_once 'inc/init.php';
     genericAssertion('object_id', 'uint0');
     $tags = isset($_REQUEST['taglist']) ? $_REQUEST['taglist'] : array();
     $num_tags = count($tags);
     rebuildTagChainForEntity('object', $_REQUEST['object_id'], buildTagChainFromIds($tags), TRUE);
     sendAPIResponse(array(), array('message' => 'updated tags successfully', 'object_id' => $_REQUEST['object_id'], 'num_tags' => $num_tags));
     break;
     // sync a switch or PDU's ports using SNMP
     //    UI equivalent: /index.php?module=redirect&page=object&tab=snmpportfinder
     //    UI handler: querySNMPData()
 // sync a switch or PDU's ports using SNMP
 //    UI equivalent: /index.php?module=redirect&page=object&tab=snmpportfinder
 //    UI handler: querySNMPData()
 case 'snmp_sync_object':
     require_once 'inc/init.php';
     require_once 'inc/snmp.php';
     global $log_messages;
     genericAssertion('object_id', 'uint0');
     genericAssertion('ver', 'uint');
     $object_id = $_REQUEST['object_id'];
Beispiel #5
0
function rollTags()
{
    assertStringArg('sum', TRUE);
    assertUIntArg('realsum');
    if ($_REQUEST['sum'] != $_REQUEST['realsum']) {
        return showFuncMessage(__FUNCTION__, 'ERR');
    }
    // Even if the user requested an empty tag list, don't bail out, but process existing
    // tag chains with "zero" extra. This will make sure, that the stuff processed will
    // have its chains refined to "normal" form.
    $extratags = isset($_REQUEST['taglist']) ? $_REQUEST['taglist'] : array();
    $n_ok = 0;
    // Minimizing the extra chain early, so that tag rebuilder doesn't have to
    // filter out the same tag again and again. It will have own noise to cancel.
    $extrachain = getExplicitTagsOnly(buildTagChainFromIds($extratags));
    foreach (listCells('rack', getBypassValue()) as $rack) {
        if (rebuildTagChainForEntity('rack', $rack['id'], $extrachain)) {
            $n_ok++;
        }
        amplifyCell($rack);
        foreach ($rack['mountedObjects'] as $object_id) {
            if (rebuildTagChainForEntity('object', $object_id, $extrachain)) {
                $n_ok++;
            }
        }
    }
    return showFuncMessage(__FUNCTION__, 'OK', array($n_ok));
}
Beispiel #6
0
function getImplicitTags($oldtags)
{
    global $taglist;
    $tmp = array();
    foreach ($oldtags as $taginfo) {
        $tmp = array_merge($tmp, $taglist[$taginfo['id']]['trace']);
    }
    // don't call array_unique here, it is in the function we will call now
    return buildTagChainFromIds($tmp);
}