$start = ($page - 1) * $rp;
$limit = "LIMIT {$start}, {$rp}";
$db = new ossim_db();
$conn = $db->connect();
$xml = "";
$filter = get_filters_names($conn);
$policy_list = Policy::get_list($conn, "AND ctx=UNHEX('{$ctx}') {$where} ORDER BY policy.{$order}");
if ($policy_list[0]) {
    $total = $policy_list[0]->get_foundrows();
    if ($total == 0) {
        $total = count($policy_list);
    }
} else {
    $total = 0;
}
$engine = is_ctx_engine($conn, $ctx) ? 'engine' : 'ctx';
$xml .= "<rows>\n";
$xml .= "<page>{$page}</page>\n";
$xml .= "<total>{$total}</total>\n";
if ($total > 0) {
    list($conds_list, $pol_conds) = Policy::get_conditions_hash($conn, $ctx);
}
foreach ($policy_list as $policy) {
    $id = $policy->get_id();
    $order = $policy->get_order();
    $xml .= "<row id='{$id}' col_order='{$order}' col_type='{$engine}'>";
    $tabla = "<img src='../pixmaps/tables/cross.png' border='0'/>";
    $active = !$policy->get_active() ? $tabla : str_replace("cross", "tick", $tabla);
    $xml .= "<cell><![CDATA[" . $active . "]]></cell>";
    $xml .= "<cell><![CDATA[" . $order . "]]></cell>";
    $pname = $policy->get_descr();
ossim_valid($b_week_day, OSS_DIGIT, 'illegal:' . _("Begin Day of the week"));
ossim_valid($b_hour, OSS_DIGIT, 'illegal:' . _("Begin Hour"));
ossim_valid($b_minute, OSS_DIGIT, 'illegal:' . _("Begin Minute"));
ossim_valid($e_month, OSS_DIGIT, 'illegal:' . _("End Month"));
ossim_valid($e_month_day, OSS_DIGIT, 'illegal:' . _("End Day of the month"));
ossim_valid($e_week_day, OSS_DIGIT, 'illegal:' . _("End Day of the week"));
ossim_valid($e_hour, OSS_DIGIT, 'illegal:' . _("End Hour"));
ossim_valid($e_minute, OSS_DIGIT, 'illegal:' . _("End Minute"));
ossim_valid($tzone, OSS_ALPHA, OSS_DOT, OSS_SCORE, '\\/', '\\+', 'illegal:' . _("Timezone"));
ossim_valid($event_type, OSS_DIGIT, 'illegal:' . _("Event Type"));
if (ossim_error()) {
    die(ossim_error());
}
$db = new ossim_db();
$conn = $db->connect();
$is_engine = is_ctx_engine($conn, $ctx);
/* SOURCES */
$source_ips = array();
$source_host_groups = array();
$source_nets = array();
$source_net_groups = array();
$sources = POST('sources');
if ($is_engine) {
    $source_ips[] = "any";
} else {
    $minsrc = 0;
    foreach ($sources as $source) {
        if (check_any($source)) {
            $source_ips[] = "any";
            $minsrc++;
        } else {
function get_plugin_groups($conn, $data)
{
    $id = $data['id'];
    $ctx = $data['ctx'];
    ossim_valid($id, OSS_HEX, OSS_NULLABLE, 'illegal:' . _("Policy ID"));
    ossim_valid($ctx, OSS_HEX, 'illegal:' . _("CTX"));
    if (ossim_error()) {
        $info_error = "Error: " . ossim_get_error();
        ossim_clean_error();
        $return['error'] = TRUE;
        $return['msg'] = $info_error;
        return $return;
    }
    $is_engine = is_ctx_engine($conn, $ctx);
    $result = '';
    $result .= "\n\t\t<div style='height:150px;overflow:auto'>\n\t\t<table width='100%' class='transparent' cellspacing='0' cellpadding='0'>\n\t\t\t<tr>";
    $iplugin = 1;
    /* ===== plugin groups ==== */
    if ($is_engine) {
        $pgroups = Plugin_group::get_groups_by_plugin($conn, 1505);
        $excluded = array();
    } else {
        $pgroups = Plugin_group::get_list($conn, "", "name");
        $excluded = Plugin_group::get_groups_by_plugin($conn, 1505);
    }
    foreach ($pgroups as $g) {
        if (isset($excluded[$g->get_id()])) {
            continue;
        }
        $result .= "<td class='nobborder' style='text-align:left;padding-right:10px'>";
        $checked = in_array($g->get_id(), $pgroups) ? "checked='checked'" : "";
        $mixed = $is_engine ? FALSE : $g->contains_directive_plugin($conn);
        if ($mixed) {
            $tip = _('This plugin group cannot be applied because contains the plugin 1505');
            $result .= "<input type='checkbox' class='disabled' disabled='disabled' id='plugin_" . $g->get_id() . "' pname='" . $g->get_name() . "'>";
            $result .= "<a href='modifyplugingroupsform.php?action=edit&id=" . $g->get_id() . "' class='greybox gray italic tiptip' title='" . _('View DS Group') . "'>" . $g->get_name() . "</a>";
            $result .= " <img src='/ossim/pixmaps/warnin_icon.png' id='dg_locked' class='tiptip_dg' title='" . $tip . "'/>";
        } else {
            $result .= "<input type='checkbox' id='plugin_" . $g->get_id() . "' pname='" . $g->get_name() . "' onclick='drawpolicy()' name='plugins[" . $g->get_id() . "]' {$checked}/>";
            $result .= "<a href='modifyplugingroupsform.php?action=edit&id=" . $g->get_id() . "' class='greybox' title='" . _('View DS Group') . "'>" . $g->get_name() . "</a>";
        }
        if ($iplugin++ % 4 == 0) {
            $result .= "<tr></tr>";
        }
    }
    $result .= "\n\t\t\t</tr>\n\t\t</table></div>";
    $return['error'] = FALSE;
    $return['data'] = $result;
    return $return;
}